lars wrote:
Hi,
Hello,
I am writing a package with some subs. One of these subs can be called for an
instance of the object ($obj->get_defaults()) or as a static sub
(Example::Package->get_defaults()).
The behaviour of the sub depends on the kind of call.
The following code accomplishes this goal, but it looks a bit dirty to me ...
sub get_defaults {
my $self = shift;
$self = undef if ($self eq 'Example::Package');
if (defined($self)) ....
}
Is there a cleaner way to find out, if the sub was called as an object method
or as a static sub?
You really just need to see if its a reference or not:
sub get_defaults {
my ($self) = @_;
if(ref $self) {
....
}
HTH Lars :)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>