nodebunny has asked for the wisdom of the Perl Monks concerning the following question:
package MY_STDOUT; 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;
In a more Perl-Moosy way? For example should I douse MY_STDOUT; print "content-type: text/html\n\n"; #try commenting out this line print "<html>\n"; print "</html>\n";
in a BUILD{} function? Would it make more sense to implement this as a Moosy class or as Moose::Role? And finally, would I have to do something likeopen(TRUE_STDOUT, '>', '/dev/stdout'); tie *STDOUT, __PACKAGE__, (*STDOUT);
to use it?my $MY_STDOUT = MY_STDOUT->new();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wrapping Tie with Moose or Moose::Roles
by Anonymous Monk on Sep 29, 2011 at 08:52 UTC | |
|
Re: Wrapping Tie with Moose or Moose::Roles
by Anonymous Monk on Sep 29, 2011 at 06:56 UTC |