Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub CheckPrintOutput
- {
- my @output = @_; # args passed to print eventually find their way here.
- foreach my $value (@output) {
- Log->log($value) if $value =~ /warning|error|notice|attention/i;
- }
- }
- package IO::Override;
- use base qw<Tie::Handle>;
- use Symbol qw<geniosym>;
- sub TIEHANDLE { return bless geniosym, __PACKAGE__ }
- sub PRINT {
- shift;
- # You can do pretty much anything you want here.
- # And it's printing to what was STDOUT at the start.
- #
- print $OLD_STDOUT join( '', 'NOTICE: ', @_ );
- }
- tie *PRINTOUT, 'IO::Override';
- our $OLD_STDOUT = select( *PRINTOUT );
- sub PRINTF {
- shift;
- # You can do pretty much anything you want here.
- # And it's printing to what was STDOUT at the start.
- #
- my $format = shift;
- print $OLD_STDOUT join( '', 'NOTICE: ', sprintf( $format, @_ ));
- }
- open my $fh, ">log.txt";
- print "test1n";
- my $current_fh = select $fh;
- print "test2n";
- select $current_fh;
- print "test3n";
- package PsychicSTDOUT;
- use strict;
- my $c = 0;
- my $malformed_header = 0;
- open(TRUE_STDOUT, '>', '/dev/stdout');
- tie *STDOUT, __PACKAGE__, (*STDOUT);
- sub TIEHANDLE {
- my $class = shift;
- my $handles = [@_];
- bless $handles, $class;
- return $handles;
- }
- sub PRINT {
- my $class = shift;
- if (!$c++ && @_[0] !~ /^content-type/) {
- my (undef, $file, $line) = caller;
- print STDERR "Missing content-type in $file at line $line!!n";
- $malformed_header = 1;
- }
- return 0 if ($malformed_header);
- return print TRUE_STDOUT @_;
- }
- 1;
- use PsychicSTDOUT;
- print "content-type: text/htmlnn"; #try commenting out this line
- print "<html>n";
- print "</html>n";
Add Comment
Please, Sign In to add comment