in reply to Using External Subroutines in a Perl Object file (Package Module)

Without having read much of your code, the line 'require xxx.pl' already tells me that you are doing it the really old-fashioned way (lets call it the perl4 approach). To add utility subroutines there are a few more modern ways:

1. The perl5 approach
Using a module called Exporter you create a module that you load with a 'use mymodule(a,b,c);' statement. Subsequently the subroutines a b and c will be part of your name space (and also any subroutines that are included by default). Just do 'perldoc Exporter', it is a core module since the beginning of perl5

2. The perl5 object oriented approach
You've got objects already. Nothing simpler than to make them inherit subroutines from a common ancestor. Create a class and change the subroutines to methods in that class, then add 'use base myutilityclass;' and adapt your new subroutine and the subroutines are methods of your class. Check out 'perldoc perlobj' and 'perldoc base'. If you have a recent perl version, use 'parent' instead of 'base'

3. The Perl6 approach
Don't fear, you don't need perl6 for this. There is a module called moose that offers a modern interface to objects similar to the object system built into Perl6 and somewhat similar to other languages like Java. Moose has Roles. Roles are (basically) additional methods, variables and/or requirements you can simply add to objects like lego blocks to your lego house. 'perldoc moose' gets you filled in on the details (after you installed it from CPAN). Or read about it on the internet or on perlmonks.

  • Comment on Re: Using External Subroutines in a Perl Object file (Package Module)

Replies are listed 'Best First'.
Re^2: Using External Subroutines in a Perl Object file (Package Module)
by physeetcosmo (Initiate) on Aug 26, 2010 at 01:37 UTC
    You rock, let me restructure and test it out. This code base is about 3 years old, so not surprised that you are saying it looks old :)