Greetings fellow Monks!

Ok, I have this simple and basic OO hiarchy:

Object.pm:
package Object; use strict; use warnings; sub new { my ($class) = @_; my $self = { _object => $class, }; bless $self, $class; return $self; } sub toString { my $self = shift; return $self->{'_object'}; } 1

Bah.pm:
package Bah; use lib "."; use Object; use strict; our @ISA = qw(Object); # inherits from Object # Create Object class instance #my $Object = Object()->new(); sub new { my ($class) = @_; my $self = $class->SUPER::new(@_); $self->{'_bah'} = 0; return $self; } sub printBah { my $self = shift; print "Bah\n"; } 1

And a simple test script to see that Bah inherits:

objtests.pl:
use lib "."; use Bah; use strict; use Data::Dumper; my $bah = Bah->new(); print $bah->toString() . "\n"; $bah->printBah();
This works as it should. Bah inherits from Object. Now my question is if you guys here can give me ideas on how to from within this objtests using the object ref $bah getting all methods this object has!? Something like: $bah->_methods; would return "new", "printBah" and "toString". As usuall with perl I bet there are different methods to get this information and I wanna find the "best" way. I wanna avoid having to put the methodnames in the object itself somehow (EXPORT?), so I dont have to update this list everytime I add a new method. I can also parse the code, but I was hoping for a more OO/clean way...

Ideas?

Thanks,
Ace

In reply to Getting methods existing in a Perl Object! by Ace128

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.