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
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
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...use lib "."; use Bah; use strict; use Data::Dumper; my $bah = Bah->new(); print $bah->toString() . "\n"; $bah->printBah();
In reply to Getting methods existing in a Perl Object! by Ace128
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |