Before release it I want the opinion of the monks, and some help to find a good name for the Perl Module.
Example of class:
## Example of use of the class:class Foo extends Bar { use LWP::Simple qw(get) ; ## import the method get() to this package +. vars ($GLOBAL_VAR) ; ## same as: use vars qw($GLOBAL_VAR); my ($local_var) ; ## constructor/initializer: sub Foo { $this->{attr} = $_[0] ; } ## method with input variables declared: sub get_pages ($base , \@pages , \%options) { my @htmls ; if ( $options{proxy} ) { ... } foreach my $pages_i ( @pages ) { my $url = "$base/$pages_i" ; my $html = get($url) ; push(@htmls , $html) ; $this->cache($url , $html) ; } return @htmls ; } ## method like a normal Perl sub: sub cache { my ( $url , $html ) = @_ ; $this->{CACHE}{$url} = $html ; } }
As you can see you don't need to declare the method new and the variable $this in each method. The inputs of a method can also be declared in the header of the sub, soo you don't need to make:package main ; my $foo = new Foo(123) ; $foo->get_pages('http://www.perlmonks.com/', ['/index.pl','/foo'] , +{proxy => 'localhost:8080'}) ;
You just make:sub test { my $this = shift ; my ( $arg1 , @list ) = @_ ; $this->other(...); }
Other good thing is to can declare the reference to an Array or Hash, and already have a variable loading them:sub test ($arg1 , @list) { $this->other(...); }
To delcare the method above in the normal way you need to do all of this:sub testref ($arg1 , \@list , \%hash) { $this->other(...); } ## use: $object->testref("foo" , [1,2,3] , {k1 => 1})
You can see that all the objects are a HASH reference, soo, all the attributs stay at $this->{keyx} ;sub testref { my $arg1 = $_[0] ; my @list = @{$_[1]} ; my %hash = %{$_[2]} ; $this->other(...); }
I will appreciate any type of feedback and suggestions for new things.
The purpose of this module is to bring an easy way to declare classes in Perl, and with less code.
Update: multiple-inheritance implemented:
class Foo extends Bar, Baz {...}
Graciliano M. P.
"Creativity is the expression of the liberty".
|
|---|