Probably, what you want is something like:
package Foo;
sub new { # A noop constructor
bless {}, shift;
}
sub frobnicate {
my($self, @args) = @_;
unless($self eq 'Foo' || (ref $self && $self->isa('Foo'))) {
unshift @args, $self;
undef $self;
}
# Now $self is available only if you have an OO call
# List of @args is always the same
return join(', ', @args). "\n";
}
and use it in the following way:
my $f = Foo->new();
print $f->frobnicate('my','args');
# or
print Foo::frobnicate('my','args');
# or even
print Foo->frobnicate('my','args');
Beware, though that doing something like $self->isa('Foo') breaks inheritance mechanisms and IMHO it is a Bad Thing (tm).
As usual, perl "gives you enough rope to hang yourself", which is a Good Thing (tm) :-)
|