Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Moose and File::Temp

by gsiglet (Acolyte)
on Nov 19, 2012 at 13:53 UTC ( #1004542=note: print w/ replies, xml ) Need Help??


in reply to Moose and File::Temp

Are your remarks relevant to the following issue as well?

package test; use Moose; use FileHandle; has 'fh' => ( is => 'rw', isa => 'FileHandle', lazy => 1, default => sub { FileHandle->new }, ); sub BUILD { my $self = shift; open $self->{fh} , "<", "temp.txt"; while (<$self->{fh}>) { print $_; } }
This also throws an error:
Syntax error at test.pm line 17, near "<$self->{fh"


Comment on Re: Moose and File::Temp
Select or Download Code
Re^2: Moose and File::Temp
by tobyink (Abbot) on Nov 19, 2012 at 14:05 UTC

    You may have some difficulty with isa => 'FileHandle' because while FileHandle is a core Perl module, Moose uses the type constraint string "FileHandle" to refer to unblessed Perl file handles - i.e. not objects created by the FileHandle package.

    open my $fh , "<", "temp.txt"; $self->fh($fh); while (<$fh>) { print $_; }
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      So it is impossible to use  while(<$self->{IamAfileHandleAttribute}>) { ... } > to read a file, outside my constructor. I guess I will have to do:
      my $temp_fh = $self->{IamAfileHandleAttribute}; while (<$temp_fh>) { ... }
        So it is impossible to use while(<$self->{IamAfileHandleAttribute}>) { ... } > to read a file
        no, it's not really impossible. you can just use readline instead of the diamond operator.
        while (readline $self->{IamAfileHandleAttribute}) {

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004542]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-12-17 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (34 votes), past polls