I'm finishing a Perl Module that implements the popular way to declare classes in Perl. The idea came from the Java programmers that we have here, that thinks that the way to declare classes in Perl is ugly, soo I have used Filter::Simple to declare the classes in Perl similar to Java. Now the Java programmers can work better with Perl.

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:

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 ; } }
## Example of use of the class:
package main ; my $foo = new Foo(123) ; $foo->get_pages('http://www.perlmonks.com/', ['/index.pl','/foo'] , +{proxy => 'localhost:8080'}) ;
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:
sub test { my $this = shift ; my ( $arg1 , @list ) = @_ ; $this->other(...); }
You just make:
sub test ($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 testref ($arg1 , \@list , \%hash) { $this->other(...); } ## use: $object->testref("foo" , [1,2,3] , {k1 => 1})
To delcare the method above in the normal way you need to do all of this:
sub testref { my $arg1 = $_[0] ; my @list = @{$_[1]} ; my %hash = %{$_[2]} ; $this->other(...); }
You can see that all the objects are a HASH reference, soo, all the attributs stay at $this->{keyx} ;

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".


In reply to new Class:: module to declare classes in Perl in the popular way: class foo extends bar { sub x($var){..} } by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.