Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^8: Moo and Spreadsheet::ParseExcel (explain?)

by tye (Cardinal)
on Nov 17, 2012 at 19:29 UTC ( #1004343=note: print w/ replies, xml ) Need Help??


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

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        


Comment on Re^8: Moo and Spreadsheet::ParseExcel (explain?)
Re^9: Moo and Spreadsheet::ParseExcel (explain?)
by tobyink (Abbot) on Nov 17, 2012 at 23:45 UTC

    "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?)."

    Moo::Role loops through the list of roles with a for loop, using the default loop variable, global $_. (Or rather it did, as this is now fixed.)

    In for loops, the loop variable is an alias into the array. If you assign to it, the original array is altered. Thus within that loop, if $_ were assigned to, it would alter the list of roles.

    Now, what happens within the loop? The role modules get required. And thus any modules that the role modules use get loaded too. And in all that code that gets loaded, somewhere, undef gets assigned to global $_. (And no, I don't know exactly where... Spreadsheet::WriteExcel has a number of dependencies.)

    That's how undef gets into @roles.

    "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."

    Role::Tiny has:

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

      Ah. Thanks. What I was missing was that there was an unspecified outer layer that was calling Moo::Role, not just the inner layer that also used Moo::Role (as well as Spreadsheet::ParseExcel).

      So it was a standard mistake of calling out to arbitrary code while using $_. And there is a spot somewhere in Spreadsheet::ParseExcel that it would be good to add local $_ to.

      - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-08-30 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls