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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.