http://www.perlmonks.org?node_id=1232977

talexb has asked for the wisdom of the Perl Monks concerning the following question:

I have a module like this:

package Foo; sub aa { my ( $self, $args ) = @_; my $val = $self->_aa ( $args->{'bar'} ); } sub _aa { my $self, $quux ) = @_; } sub bb { my ( $self, $args ) = @_; my $val = $self->_bb ( $args->{'foo'} ); } sub _bb { my $self, $fazoo ) = @_; }
and I'd like to break it up into smaller modules. The normal sub names are public methods, and the sub names with the leading underbar are private methods, so the private methods could go into another module. I managed to do
package Foo::Bar; sub _aa { my $self, $quux ) = @_; } ..
and call that as
package Foo; sub aa { my ( $self, $args ) = @_; my $val = Foo::Bar::_aa ( $self, $args->{'bar'} ); } ..
but that's a bigger change than I'd like, and isn't as clean as the original.

I'd like to be able to have Foo::Bar (with the _aa method, and others) just be more of the Foo class (so I could still call $self->_aa in Foo, but the sub _aa would live in Foo::Bar. There's a way, but my digging so far hasn't uncovered it.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.