Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Another "Find the bug!" Node

by Ovid (Cardinal)
on Sep 27, 2006 at 14:36 UTC ( #575160=perlmeditation: print w/ replies, xml ) Need Help??

Much fun was spent today tracking down a mysterious bug. I even had fun shoving a coderef into @INC to find out what was loading the errant module. I've now reproduced a minimal test case. Once I put it together, the bug was clear, but before that, there were many red herrings. Here's a minimal test case.

package Package1; use base 'Exporter'; our @EXPORT_OK = qw/this that/; our %EXPORT_TAGS = ( all => [qw/this that/], ); sub this { 'this' } sub that { 'that' } 1;

And another package:

package Package2; use base 'Exporter'; use Package1 ':all'; our @EXPORT_OK = ( @Package1::EXPORT_OK, 'foobar' ); our %EXPORT_TAGS = %Package1::EXPORT_TAGS; push @{ $EXPORT_TAGS{all} } => 'foobar'; sub foobar { 'foobar' } 1;

Do you see the bug? That was very, very annoying, but fortunately the fix is easy. If you see the bug, post it as a spoiler.

Cheers,
Ovid

New address of my CGI Course.

Comment on Another "Find the bug!" Node
Select or Download Code
Re: Another "Find the bug!" Node
by ikegami (Pope) on Sep 27, 2006 at 15:28 UTC
Re: Another "Find the bug!" Node
by herveus (Parson) on Sep 27, 2006 at 15:38 UTC
Re: Another "Find the bug!" Node
by jimt (Chaplain) on Sep 27, 2006 at 16:14 UTC

    For those people trying to figure out the problem on their own...I had all sorts of trouble figuring out the problem here, due to the test script I had set up.

Re: Another "Find the bug!" Node
by diotalevi (Canon) on Sep 27, 2006 at 17:03 UTC
Re: Another "Find the bug!" Node
by ambrus (Abbot) on Sep 27, 2006 at 17:07 UTC
Re: Another "Find the bug!" Node
by shmem (Canon) on Sep 27, 2006 at 17:36 UTC

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Another "Find the bug!" Node
by talexb (Canon) on Sep 28, 2006 at 13:24 UTC

    I'll reveal my ignorance by saying this is all a bit esoteric for me. What were you trying to do with Package1 and Package2?

    Yes, I read the spoilers.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      I can't quite say for NDA reasons, but someone wrote a package, Package2, which attempted to provide all of Package1's functionality. They also added an extra subroutine, 'foobar', which could be exported. However, if something in your codebase loads Package2 and later you try to load Package1, it's already loaded and when it tries to export 'foobar', it blows up because it doesn't have it. The solution is to do a deep copy on the arrays. Otherwise, because Package2 has a reference to an array in Package1, modifying the array in Package2 modifies the same array in Package1. Does that make sense?

      I know it sounds a bit convoluted, but there it is :)

      Cheers,
      Ovid

      New address of my CGI Course.

        Yes, now that makes sense .. thanks. That might provide an interesting topic for a Meditation, about the pitfalls surounding the construction of a wrapper for a Perl module.

        Having written TSR's in both assembler and C for DOS, I understand how things can get a little mind-bendingly complicated.

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-11-26 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls