I have a method modifier like so:
before 'wafer' => sub{
my $self = shift;
if ( ! $self->_wafer_parse_complete ){ $self->_wafer_parse };
};
The
_wafer_parse sub has a while loop in it.
If I call
$obj->wafer( '01' ) a single time, all is well. If I call
$obj->wafer( '05' ) a second time with a new value, I get this error:
Use of uninitialized value in subroutine entry at Class/MOP/Method/Wra
+pped.pm line 47
Can't use string ("") as a subroutine ref while "strict refs" in use a
+t Class/MOP/Method/Wrapped.pm line 47.
I have found that by changing the
while loop to a
foreach loop, the problem goes away.
I am using the
while loop to read through a file, so I don't want to use
foreach.
Has anyone else had this problem or know of how to fix this? I am using Moose 0.65 and ActiveState Perl 5.10.0. I tried Google search and supersearch, but I couldn't find anything.
Thanks, David
Update1:
one of the strange things, is that _wafer_parse is only ever called for the first instance becuase it sets the _wafer_parse_complete sub to a true value. Just having the while loop in the sub causes this to die, not actually running the sub twice.
Update2:
The method _wafer_parse is something like this. This fails:
sub _wafer_parse {
my $self = shift;
open my $FILE, "<", $self->{file};
while ( <$FILE> ){};
close $FILE;
}
If I removed the open command, the subroutine runs fine.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.