>>>>> "R" == RedGrittyBrick <> writes:
R> An instance method in traditional Perl OO might be like this.
R> Package Foo;
R> ...
R> sub bar {
R> my $self = shift;
R> my ($x, $y, $z) = @_;
R> ...
R> }
R> I'd like to be able to invoke this either as a (static) class method
R> $result = Foo::bar(1,2,3);
that is not a method at all. that is a plain sub call. the only way to
tell if it isn't a method is to check the first arg and see if it is a
blessed object of that class.
R> or as an instance method
R> my $foo = Foo->new(Foo::INVERTED);
that is a class method call
R> $result = $foo->bar(1,2,3);
that is an instance or object method call. those you can differentiate
by looking at the first arg. but it is a BAD idea for one method to
support both styles. there are idioms for allowing the new() (or other)
methods work both ways but it is better to have different methods for
each api style
R> What is the usual idiom for checking for the presence of the class ref?.
there is no standard way to tell a method call from a plain sub call as
you never want to use the same sub both ways. if you could call a method
without its object, what is the point of making it a method to begin
with?
uri
--
Uri Guttman ------
--------
http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ----
http://bestfriendscocoa.com ---------