On Jan 4, 2004, at 6:18 PM, r huber wrote:


I am writing several subroutines that I want to make
available to other programs without directly including
the code in those programs. Can anyone explain how to
do this or where to go to find out how to do it.

Tim and Owen have offered the quick look answer.


I personally would start with

perldoc h2xs

since that will help frame out your perl module
in a way that will allow you to install it either
canonically like any other CPAN module -
cf:
<http://www.wetware.com/drieux/CS/Proj/Wetware_ps/ index.html#id3154425254>


for the perl 5.8.1 stype generation of a simple
perl module frame work.

then of course you will also want to read

perldoc
perlmod Perl modules: how they work
perlmodlib Perl modules: how to write and use
perlmodstyle Perl modules: how to write modules with style
perlmodinstall Perl modules: how to install from CPAN
perlnewmod Perl modules: preparing a new module for distribu
tion


My basic template for a perl module is:

        package Foo::Bar;
        
        use 5.006;
        use strict;
        use warnings;
        
        #our @ISA = qw(PARENT_CLASS);
        
        our $VERSION = '0.01';
        #---------------------------------
        # Our Stock Constructor
        # note: <http://www.perlmonks.org/index.pl?node_id=52089>
        sub new
        {
                my $class = shift;
                my $self = {};
                bless $self, $class;
        
        } # end of our simple new
        
        #---------------------------------
        # so that AUTOLOAD finds one here
        
        sub DESTROY {}
        
        #
        # your methods here
        #
        
        1; # so that the 'use Foo::Bar'
           # will know we are happy

this way I can do the shorter set up of

use Foo::Bar;

my $foo = new Foo::Bar;

my @responses = $foo->function_name_here(@arglist);

and all I would do to shift a standard 'function' that
I already had as say

        sub function_name_here
        {
                my ( $first, $second, $third ) = @_ ;
                ...
        }

would be to pull off the class or instance reference:


sub function_name_here { my $me = shift; my ( $first, $second, $third ) = @_ ; ... }

so that I can avoid the whole question of exporting
fundtion names, that is detailed in

perldoc Exporter

I of course would recommend that you
pick up a copy of
<http://www.oreilly.com/catalog/lrnperlorm/>


ciao drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to