Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Perl Privvies

by Aristotle (Chancellor)
on Jul 16, 2006 at 19:13 UTC ( [id://561591]=note: print w/replies, xml ) Need Help??


in reply to Perl Privvies

I like to write my code like so:

package Some::Module; our $VERSION = '0.1'; our @ISA = qw( Super::Module ); package Some::Module::YeWhoEnters; sub pfoo { # ... } sub xbar { my ( $foo, $bar ) = @_; # ... my $baz = pfoo( $bar ); # ... } sub Some::Module::new { my $class = shift; # ... return xbar( $_ ); }

This way, everything is in a private package by default, and things only get into the publically documented package only when explicitly declared to belong there. At the same time, file-level lexicals are in scope during all of the code, and I can call private functions without having to prefix them with fully qualified package names. This is decent encapsulation, since you cannot accidentally call private functions as methods on the blessed reference without tricks, and you cannot invoke them as functions without the ::YeWhoEnters moniker either.

It’s a bit annoying that this setup breaks the ->SUPER::foo notation in Perl because that is based on the compile-time package of a method, but then I use SUPER nowadays anyway which makes that a non-issue.

But note that it’s not really possible to make this work for private methods without defeating the encapsulation.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: Perl Privvies
by ikegami (Patriarch) on Jul 17, 2006 at 01:46 UTC
    *Some::Module::YeWhoEnters::ISA = \@Some::Module::ISA;

    would allow ->SUPER::...() to work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-28 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found