(= In the dictionary next to the word "klunky", it has a picture of perl's OO stuff.
Don't get me wrong, I don't mind it.. I find perl's OO much more intuitive than C++'s... I ended up learning java to learn how OO should be done...
Once you get a package set up, the calls from the instantiation script are a breeze. It's the package setup that suxors.
Here's a demo of how I generally set up packages:
Code:
#!/usr/bin/perl
use strict;
use warnings;
## filename: MyPackage.pm
package MyPackage;
my($name) = "MyPackage";
sub new {
my($creator) = shift;
my($class) = ref($creator) || $creator;
my($self) = {
dataPath => "/path/to/stuff/",
otherThing => "this or that",
};
return bless($self, $class);
}
sub someFunction($$)
{
my($self) = shift;
my($data) = shift ||
die "$name: someFunction: Did not receive data\n";
doSomethingWithData($data);
}
1;
And the invocant script:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use lib '/path/to/custom/packages/';
use MyPackage;
my($pkg) = new MyPackage();
$pkg->doSomething("Data to manip/use");
print "Data path is: $pkg->{dataPath}\n";
exit;
That's a bare-bones, anyway.. (=