I think the concept that you are looking for is 'Object inheritance'. (the exact term, to tell a scalar what package it belongs to is bless
my $local1 = my_module->new(); $local1->func1(); $local1->func2(); my $local2 = my_module->new(); $local2->func1(); $local2->func2(); package my_module; use base qw(a_module); sub func1 { shift->do_something1() } sub func2 { shift->do_something2() }
This will work so long as a_module is set up correctly for inheritance. If it isn't (you can tell because ref($local1) will be 'a_module' and not 'my_module'), it'll behave the same way you've been having problems with, and you'll need to add within your package:
sub new { my $class = shift; return bless a_module->new(), ref($class) || $class; }
In reply to Re: Typecasting a scalar to a module
by jhourcle
in thread Typecasting a scalar to a module
by thekestrel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |