Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Private Methods Meditation

by hardburn (Abbot)
on Jul 19, 2004 at 12:47 UTC ( [id://375534]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Private Methods Meditation
in thread Private Methods Meditation

sub method2 { my $self = shift; _method1( $self ); }

or am I missing something really obvious in this example ?

Yes. If you don't override _method1 in the subclass, nothing will be called.

----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Replies are listed 'Best First'.
Re^4: Private Methods Meditation
by guha (Priest) on Jul 19, 2004 at 16:12 UTC
      Let's extend the example a little. What if _method1 isn't defined, but is AUTOLOAD'ed instead? This isn't an unreasonable thing. So far, so good.

      Now, let's say that the Foo class inherits from some CPAN module. This is a very common thing. Let's say we're inheriting from CGI::Application.

      Now, let's say that CGI::Application adds a _method1() in the next version. Uh-oh. Your code breaks in very mysterious ways.

      What if CGI::Application adds dependence on AUTOLOAD in the next version. Uh-oh. Your code breaks again, but in even _MORE_ mysterious ways. (Cause it's not your code that broke, but it sure looks like it!)

      Perl6 fixes most (but not all) of these issues, which is a "Good Thing"™

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

        A side note. AUTOLOAD is already unreasonable. The only place I expect to find that is in code like Class::Delegation and Win32::OLE where the total of methods cannot be known during compile time.

        When I consider this: an object only uses method call syntax when inheritance is intended to be at work. If the author of the subclassed module didn't intend for the _method to be overrideable then it wouldn't be called with -> method syntax. If you intend to call _method and define it privately then you ought to be calling it as _method( $self ... ). Alternatively, if you want to use inheritance internally for your private methods then you have to be explicit about the package: $self->Foo::Bar::_method( ... ).

      So what happens when the method needs to access the class data?

      ----
      send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375534]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found