Forum Moderators: coopster & phranque

Message Too Old, No Replies

A bit of OO help.

Want to make a 'new' something

         

Dabrowski

1:23 am on Mar 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, if this is too much to explain in one thread, please point me at a good website.

Basically, I have my modules, but they're really not modules, just an extention of my existing code.

For example, in my main script I simply have:
[perl]use myMod;

myMod::myFunc( $thisandthat);
[/perl]

And in my module just:
[perl]package myMod;

...code...

1;
[/perl]

But how do I actually make it a module, as in my main script actually says:
[perl]use myMod;

my $mod = new myMod;

$mod -> myFunc( @stuff);
[/perl]

phranque

6:21 am on Mar 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you put the myMod code in a file named myMod.pm and put it in a lib directory, which you can specify with a directive in your main script:
use lib "/path/to/local_lib";

you can structure your modules by putting them in subdirectories.
so if you put your module code in /path/to/local_lib/FOO/myMod.pm you could do something like:
use lib "/path/to/local_lib";
use FOO::myMod;
...

type "perldoc perlmod" for the online doc...

perl_diver

10:19 am on Mar 8, 2008 (gmt 0)

10+ Year Member



You also have to write a "new" method if you haven't already. Perl comes with two or three object oriented tutorials, you can also look them up on the perldoc.perl.org website in the "tutorials" section.