Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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'

Replies are listed 'Best First'.
Re^6: Moo and Spreadsheet::ParseExcel
by karlgoethebier (Monsignor) 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,


    «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 (Monsignor) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003110]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-02-25 06:10 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.