nodebunny has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to implement a Moosy Tie/Handler, but I have this problem where whenever i call tie, I get an error "cant find TIEHANDLE" -- examples I've seen so far use a non-Moosy implementation, is there anyway to do this:
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;
use MY_STDOUT; print "content-type: text/html\n\n"; #try commenting out this line print "<html>\n"; print "</html>\n";
In a more Perl-Moosy way? For example should I do
open(TRUE_STDOUT, '>', '/dev/stdout'); tie *STDOUT, __PACKAGE__, (*STDOUT);
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 like
my $MY_STDOUT = MY_STDOUT->new();
to use it?

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

    I can't exactly wrap my head around ...

    Classic negative feedback -- back away happy