UNSUBSCRIBE please!!
From: "Martin Moss" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
CC: <[EMAIL PROTECTED]>
Subject: listing subroutines defined locally in a class
Date: Fri, 10 Jan 2003 18:56:13 -0000
All,
I want to be able to take a class and in it's 'new' subroutine do a check to ensure that each class has been given configuration information for each subroutine it has defined locally within that class. The problem I have is that I don't know how to differentiate between methods created in a base class, methods created by included modules (through the use of the use) and so on. I simply only want those that exist locally to the class.
I came across the following code :-
sub methods
{
my $self = shift;
my $class = ref($self) || $self;
my @list;
no strict 'refs';
print STDERR Dumper(keys %{"${class}::"});
# Based on methods_via() in perldb5.pl
foreach my $name (grep {defined &{${"${class}::"}{$_}}} keys %{"${class}::"}) {
push @list, $name;
}
return \@list;
}
But this doesn't quite work out, without having a long list of 'ignore' keywords. And then it wouldn't be very future proof. Does anybody have any ideas?
Regards
Marty
################################
Example of How I see this working, parent and base classes:-
package ParentClass;
use base qw(BaseClass);
use vars qw(%methods);
%methods=(
'_load' => $configdata,
'list' => $configdata,
'anothersub' => $configdata,
);
package BaseClass;
sub new
{
blahusualblah
$self->_check_methods();
}
sub methods
{
#returns a list of methods for this class, which doesn't include special ones like BEGIN, croak, AUTOLOAD etc...
}
sub _check_methods
{
my $self=shift;
my $class=ref($self)||$self;
my @methods=@{$self->methods()};
foreach my $method (@methods)
{
unless (exists($self->methods->{$method}))
{
die "No configuration supplied for $method for $class";
}
}
}
_________________________________________________________________
The new MSN 8 is here: Try it free* for 2 months http://join.msn.com/?page=dept/dialup
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs