You might also use UNIVERSAL::can(), which might make the OO interface slightly more regular:

c:\@Work\Perl\monks>perl -wMstrict -le "print qq{perl version: $] \n}; ;; use constant { STUFF => { 'bizz' => 'foe', 'bazz' => 'fie', 'bozz' => 'fee', 'buzz' => 'wiz', }, }; ;; my $obj = Kid->new; ;; my $n = 0; ;; METAMETHOD: for my $meta_method (qw/bizz buzz bazz zotz bozz/) { if (not exists STUFF->{$meta_method}) { print qq{no method corresponds to '$meta_method'}; next METAMETHOD; } ;; my $method = STUFF->{$meta_method}; ;; my $coderef = $obj->can($method); if (not $coderef) { print qq{cannot '$meta_method'->'$method' on }, ref $obj; next METAMETHOD; } $coderef->($obj, $method, $n++); } ;; { package Dad; ;; sub new { my $class = shift; return bless \my $x => $class; } sub fee { my $self = shift; $self->all(@_); } sub all { my $self = shift; print qq{method '$_[0]', n == $n}; } } ;; { package Kid; ;; use parent -norequire, qw(Dad); sub new { my $class = shift; return $class->SUPER::new; } sub fie { my $self = shift; $self->all(@_); } sub foe { my $self = shift; $self->all(@_); } } " perl version: 5.008009 method 'foe', n == 1 cannot 'buzz'->'wiz' on Kid method 'fie', n == 2 no method corresponds to 'zotz' method 'fee', n == 3
Note the
    $coderef->($obj, $method, $n++);
syntax for the code reference method call.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Calling a subroutine when part of call is a variable Contant by AnomalousMonk
in thread Calling a subroutine when part of call is a variable Contant by Anonymous Monk

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.