Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Wrapping Tie with Moose or Moose::Roles

by nodebunny (Novice)
on Sep 29, 2011 at 02:38 UTC ( [id://928457]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://928457]
Approved by ww
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-03-28 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found