@@ -69,7 +69,7 @@ sub __run__ {
69
69
%opts = Rex::Args-> getopts;
70
70
71
71
if ( $opts {' Q' } ) {
72
- my ( $stdout , $stderr ) ;
72
+ my $stdout ;
73
73
open ( my $newout , ' >' , \$stdout );
74
74
select $newout ;
75
75
close (STDERR );
@@ -744,14 +744,11 @@ sub load_rexfile {
744
744
}
745
745
};
746
746
747
- my ( $stdout , $stderr , $default_stderr );
748
- open $default_stderr , " >&" , STDERR ;
749
-
750
- # we close STDERR here because we don't want to see the
751
- # normal perl error message on the screen. Instead we print
752
- # the error message in the catch-if below.
753
- local *STDERR ;
754
- open ( STDERR , " >>" , \$stderr );
747
+ # we don't want to see the
748
+ # normal perl warning message on the screen. Instead we print
749
+ # the warning message in the catch-if below
750
+ my @warnings ;
751
+ local $SIG {__WARN__ } = sub { push @warnings , $_ [0] };
755
752
756
753
# we can't use $rexfile here, because if the variable contains dots
757
754
# the perl interpreter try to load the file directly without using @INC
@@ -761,13 +758,19 @@ sub load_rexfile {
761
758
# update %INC so that we can later use it to find the rexfile
762
759
$INC {" __Rexfile__.pm" } = $rexfile ;
763
760
764
- # reopen STDERR
765
- open STDERR , " >&" , $default_stderr ;
766
-
767
- if ($stderr ) {
768
- my @lines = split ( $/ , $stderr );
761
+ if (@warnings ) {
769
762
Rex::Logger::info( " You have some code warnings:" , ' warn' );
770
- Rex::Logger::info( " \t $_ " , ' warn' ) for @lines ;
763
+ for (@warnings ) {
764
+ chomp ;
765
+
766
+ # remove /loader/.../ prefix before filename
767
+ s { /loader/[^/]+/} {} sxm ;
768
+
769
+ # convert Rexfile to human-friendly name
770
+ s { __Rexfile__.pm} { Rexfile} msx ;
771
+
772
+ Rex::Logger::info( " \t $_ " , ' warn' );
773
+ }
771
774
}
772
775
773
776
1;
@@ -781,6 +784,9 @@ sub load_rexfile {
781
784
# we load the Rexfile via our custom code block.
782
785
$e =~ s | /loader/[^/]+/|| smg ;
783
786
787
+ # convert Rexfile to human-friendly name
788
+ $e =~ s { __Rexfile__.pm} { Rexfile} msx ;
789
+
784
790
my @lines = split ( $/ , $e );
785
791
786
792
Rex::Logger::info( " Compile time errors:" , ' error' );
0 commit comments