Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Using eval for

by SuperCruncher (Pilgrim)
on Dec 28, 2001 at 04:13 UTC ( [id://134775]=note: print w/replies, xml ) Need Help??


in reply to Re: Using eval for
in thread Using eval for

Thanks for your reply. An eval inside an eval... strange. Let me just make sure I've got my head round that code:

eval 'package Plugin; do $plugin'; - this creates a package which the 'plugin' is evaled into.

eval { no strict refs; &{'Plugin::func'}() } - disables strict refs for the enclosing' block', then calls func in the Plugin package?

%Plugin:: = () - I've never seen that before. I didn't know a package could be viewed in a sort of 'hash context'. So that sort of 'resets' the package to undef?

BTW, the title of the node should have been "Using eval for 'plugins'" but Everything seems to have removed it in the preview stage (maybe because it didn't escape single quotes properly?).

Replies are listed 'Best First'.
Re: Re: Re: Using eval for
by chip (Curate) on Dec 28, 2001 at 04:40 UTC
    Right on all three counts. Good analysis.

    WRT the eval inside the eval: If you don't like that, you can read the file contents and then:

    eval 'package Plugin;' . $file_contents

    I just did what I did to save the trouble of open/read/close. On the other hand, the eval 'do' will hide your lexical vars from the plugin while the eval above will reveal them. Bug or feature? YOU be the judge.

    WRT the packages as hashes: Each element of %pkgname:: is a GLOB. You can do your own glob aliasing that way, and lots of other evil stuff. But beware the bandersnatch, er, beware the compiler's tendency to grab references to GLOBs and not let go even when they've been removed from their original places.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (None)
    As of 2024-04-25 01:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found