Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^5: Moo and Spreadsheet::ParseExcel

by tobyink (Abbot)
on Nov 09, 2012 at 12:21 UTC ( #1003110=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Moo and Spreadsheet::ParseExcel
in thread Moo and Spreadsheet::ParseExcel

Error reproduced! :-)

Here's a one line patch for Moo::Role that fixes your issue. I'll report it to the Moo bug tracker when I've figured out why this patch makes any difference to anything!

# Replace this sub... sub apply_roles_to_package { my ($me, $to, @roles) = @_; $me->_inhale_if_moose($_) for @roles; $me->SUPER::apply_roles_to_package($to, @roles); } # With this instead... sub apply_roles_to_package { my ($me, $to, @roles) = @_; for my $r (@roles) { $me->_inhale_if_moose($r) }; $me->SUPER::apply_roles_to_package($to, @roles); }

Update: OK, it happens because something inadvertently causes the global $_ to become undefined.

Update 2: Bug report submitted.

Update 3: patched on git.

Update 4 (about a week later): Moo 1.000006 released.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re^5: Moo and Spreadsheet::ParseExcel
Download Code
Re^6: Moo and Spreadsheet::ParseExcel
by karlgoethebier (Vicar) on Nov 09, 2012 at 13:06 UTC

    Great! But how strange. local $_ also fails. It would be very interesting to hear why this fails.

    Update: Ergo better omit $_ in general?

    Thank you very much for your help and best regards,

    Karl

    «The Crux of the Biscuit is the Apostrophe»

      my $_ should work, but local $_ would fail.

      It's because the loop variable in a for loop is an alias to each element of the array. So the global $_ is an alias into @roles in this case. Assigning to global $_ assigns into the @roles array. local (despite the name) operates on global variables, providing a local value for them, but not really creating a new local variable. So even in the scope of local $_ assigning to $_ will assign into @roles.

      It's a particular combination of Perl features which is normally fairly safe to use, but because apply_roles_to_package also happens to load modules (and thus run third-party code - i.e. code which is not part of Moo) it causes problems.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Could you try explaining this again? In particular, what is the code outside of Moo that causes $_ to exhibit this problem? It probably doesn't help that I'm not clear on how 'undef' ends up in @roles (is the code that does that shown anywhere in this thread?). I'm also unclear how the 'uninitialized' warning causes the Role::Tiny module to fail (leading to a "Compilation failed") without producing an error message.

        Thank you (in advance).

        - tye        

Re^6: Moo and Spreadsheet::ParseExcel
by karlgoethebier (Vicar) on Nov 17, 2012 at 13:02 UTC

    Thanks again for fixing this. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2015-07-05 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls