[newbie] [mp2] when are inline/anonymous subs compiled?
[prev]
[thread]
[next]
[Date index for 2005/03/09]
Hi folks, apologies if this is well known information, I did search!
My response method-handler reads a template and I want to call a different
sub for each type of 'field' I find. I also want other packages to be able
to 'register' new subs for new 'field' types. I'm not sure wether to use a
hash of anonymous subs or regular subs.
Question is, do anonymous subs assigned to hash values and placed in the
'new' method get compiled every time a new object is created or just when
the module file is initially loaded?
cheers
John
--
----------------- (more detailed info follows)
I have a templating system using a method handler for the Response phase
with non-persistent objects:
sub r ($$) {
...read template etc...
while( template matches /(field-type)/ ){
defined(&{$1}) and print &{ $1 }; #### using non-anonymous subs
## OR ## defined(&{$code{$1}}) and print &{$code{$1}}; #### using anon
subs
}
}
sub new { my $self=shift; my $code={};
#### if using anon subs, define them here:
$$code{type1} = sub { do something cool; }
$$code{type2} = sub { do something cooler; }
$$code{type3} = sub { do something even cooler; }
bless $self=>$code;
}
##### if using non-anon subs, define them here:
sub type1 { do something cool; }
sub type2 { do something cooler; }
sub type3 { do something even cooler; }
 |
[newbie] [mp2] when are inline/anonymous subs compiled?
John ORourke 20:37 on 09 Mar 2005
|