Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Breaking up a big module

by Eily (Monsignor)
on Apr 25, 2019 at 13:19 UTC ( [id://1232981]=note: print w/replies, xml ) Need Help??


in reply to Breaking up a big module

I feel like I might be missing the point, but isn't parent what you are looking for? If you have use parent 'Foo::Bar'; at the top of you Foo package, any call of the form $obj->method with $obj blessed into Foo will try to call Foo::method, and failing that, try again for every module in the @ISA list (in this case Foo::Bar).

Replies are listed 'Best First'.
Re^2: Breaking up a big module
by hdb (Monsignor) on Apr 25, 2019 at 13:34 UTC

    I was writing this code while you were posting...

    use strict; use warnings; package Foo; use parent 'Foo_Bar'; sub new { my $class = shift; return bless {}, $class; } sub aa { my ( $self, $args ) = @_; my $val = $self->_aa ( $args->{'bar'} ); print "aa\n"; } package main; my $foo = Foo->new(); $foo->aa( { arg1 => 'some' } );

    and in Foo_Bar.pm (underscore instead of :: only for my convenience):

    use strict; use warnings; package Foo_Bar; sub _aa { my( $self, $quux ) = @_; print "\t_aa\n"; } 1;
Re^2: Breaking up a big module
by LanX (Saint) on Apr 25, 2019 at 13:34 UTC
    I'd say yes ....

    ... provided all his calls are already ->method calls and all objects/$self are always blessed into Foo and never into Foo::Bar and his not trying to use SUPER ...

    In short as long as this approach doesn't lead to multiple inheritance of third party classes.

    So probably importing is safer.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      So probably importing is safer.
      It certainly is the more transparent solution, at least. But the methods that must be moved are used in a limited scope (they are private), so checking for correct calls might not be too cumbersome.

      As always, TIMTOWTDI :)

      This is probably where all the C++ books explain the difference between "is a" and "uses"...

        since I'm not a C++ programmer you might need to explain further.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found