Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Re: Re: Re: Callback Design

by saucepan (Scribe)
on Jan 16, 2001 at 06:46 UTC ( [id://52137]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Callback Design
in thread Callback Design

Is there some reason why you couldn't just have your module export the variables you'd like to expose to it's users? :)

package MyModule; use vars qw(@ISA @EXPORT_OK $name $street $city $zip); BEGIN { @ISA = qw(Exporter); @EXPORT_OK = qw($name $street $city $zip); require Exporter; } my $callback; sub set_callback(&) { $callback = shift } sub exec_callback { local(($name, $street, $city, $zip) = @_); $callback->(); } package Main; BEGIN { import MyModule qw($name $street $city $zip) } MyModule::set_callback { $name =~ /^[a-zA-Z\s]+$/ and $zip =~/^\d+$/ } +; MyModule::exec_callback('Bob', '600 1st St.', 'Beverly Hills', '90210' +) and print "Record is valid.\n";
Once MyModule was moved into it's own file, you could replace the ugly BEGIN { import ... } line with just use MyModule qw($name $street $city $zip).

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Callback Design
by MeowChow (Vicar) on Jan 16, 2001 at 07:05 UTC
    Good point, but I would ideally like to avoid polluting my module caller's namespace with a bunch of variables. If it came down to choosing between this and $$_{street}, I would probably go with the latter. What do you think?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found