in reply to Private Classes - Same or Separate Files?

Like tye, if B is strongly related to A, but useful elsewhere, I call the package My::A::B.
If, for some reason, it should _ONLY_ be called by A, I prefix an underscore, just like "private" methods.

I put everything that's large in separate files, but a simple class needed only once can as well be in the same file. I even switch packages multiple time to bundle the class to the place where it's used:

package My::A; ... package My::A::_B; sub TIESCALAR { return bless \(my $foo = $_[1]), $_[0] } sub FETCH { ${ $_[0] } } sub STORE { ${ $_[0] } = $_[1] } package My::A; sub method { my ($self, @foo) = @_; tie my $bar, 'My::A::_B', $foo[0]; ... } ...


I'd like some package NAMESPACE BLOCK syntax ;)

++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
    - Whreq

Replies are listed 'Best First'.
Re: Re: Private Classes - Same or Separate Files?
by Anonymous Monk on Mar 07, 2002 at 02:14 UTC
    The package keyword is lexically scoped, so you can do
    package My::A; ... { package My::A::_B; sub TIESCALAR { return bless \(my $foo = $_[1]), $_[0] } sub FETCH { ${ $_[0] } } sub STORE { ${ $_[0] } = $_[1] } } sub method { # Is &My::A::method. my ($self, @foo) = @_; tie my $bar, 'My::A::_B', $foo[0]; ... } ...
    Cheers,
    -Anomo