At 09:33 23.05.2001 -0700, you wrote:

> >
> > # all modules must return a value when they compile, so stick this
> > line
> > somewhere in your module -- I usually put it at the end of all my
> > declarations and before the main code.
> > return 1;
>
>This is why, when you look at someone else's module, the last line of
>"code" is usually
>  1;

Oops - you have a point.  I use plain old 1 as well -- quick typing will 
always get you in trouble :)

>new() is NOT required to make a module.
>Some sort of constructor is a good idea if you're making an object
>class, but you don't have to do objects to make a module.
>Admittedly, most of the modules I write *are* OO, but it's not
>*necessary*.
>
> > sub new()
> >    {
> >    my ($proto) = @_;
> >    my $class = ref($proto) || $proto;
> >    my $self = {};
> >    bless ($self, $class);
> >    return $self;
> >    }

You're right - but in 99% of the modules you use, they have a 
constructor.  Makes it nice and easy to keep your code straight and simple, 
since now you can say $mod->Function() instead of Module::Function.  I like 
thinking in pointers :)

>A module can be as simple as myFoo.pm:
>
>   package myFoo;
>   sub foo { print "bar!\n" }
>   1;
>
>which can be used by foo.pl:
>
>   use myFoo;
>   myFoo::foo;
>
>now say
>   perl foo.pl
>and it should respond with
>   bar!
>
>That's the simplest gist of it, though you can always use Exporter and
>objects and bootstrap some XS if you like. It's just not *required*.
>=o)

My idea was to give a template for a real-world module that a beginner 
could play around with immediately.  That's what I used for my first 
module, and it made my life so easy.  I didn't know what bless() did, but I 
did enjoy the benefits of bless()ing long before I got around to learning 
about what it actually does.  Having a guide for the more complicated stuff 
allows you to avoid future pitfalls because you've done things the safe 
way, without yet knowing why you did it that way.  Since I do this stuff 
for a living, most of the time the important thing is to get the project 
working -- figuring out how I got it to work is done on Saturday over a 
cold beer :)



Aaron Craig
Programming
iSoftitler.com

Reply via email to