I have just released the module Class::HPLOO, that anables the well know style for class declaration in Perl.

But I want know if already exists another filter that implements that, since I have looked and haven't found anything about, only Perl6::Classes that doesn't work very well, since is very easy to write a code that breaks the filter.

For me is much more easier to create a Perl Module with Class::HPLOO, since I just tell the class name and the methods, and all the OO code that I need to write is automatically done. Than I can run it as it was, or I can convert it to a normal Perl Module file, not dependent to the filter.

But what the felow monks think about it?

Just some example of syntax:

use Class::HPLOO ; class Foo extends Bar , Baz { vars ($VERSION , $GLOBAL_PUBLIC) ; $VERSION = '0.01' ; my $GLOBAL_PRIVATE ; sub Foo (%args) { $this->{X} = $args{x} ; $this->{Y} = $args{y} ; } sub x { $this->{X} } sub y { $this->{Y} } sub test_args ($x , $y , \%opts , \@list , $more ) { print ">> $x\n" ; print ">> $y\n" ; my @keys = map { $_ => 1 } (keys %opts , @list) ; print ">> $more\n" ; } sub old_style { my ( $x , $y ) = @_ ; print ">> $x , $y\n" ; } sub test_html_block { print <% html_foo>( $this->x , $this->y ) ; } <% html_foo($x , $y) <hr> X: $x , Y: $y <hr> %> }

And this will produce this PM code:

{ package Foo ; use vars qw(@ISA) ; push(@ISA , qw(Bar Baz UNIVERSAL)) ; sub new { my $class = shift ; my $this = bless({} , $class) ; my $ret_this = $this->Foo(@_) if defined &Foo ; $this = $ret_this if ( UNIVERSAL::isa($ret_this,$class) ) ; $this = undef if ( $ret_this eq '0' ) ; return $this ; } sub CLASS_HPLOO_HTML { return '' if !$CLASS_HPLOO_HTML{$_[0]} ; no strict ; return eval( ${$CLASS_HPLOO_HTML{$_[0]}}[0] . " <<CLASS_HPLOO_HTML +; \n". ${$CLASS_HPLOO_HTML{$_[0]}}[1] ."CLASS_HPLOO_HTML\n" . (shift +)[1]) if ( ref($CLASS_HPLOO_HTML{$_[0]}) eq 'ARRAY' ) ; return eval("<<CLASS_HPLOO_HTML; \n". $CLASS_HPLOO_HTML{$_[0]} ."CLASS_HPLOO_HTML\n" . (shift)[1] ) + ; } use vars qw($VERSION $GLOBAL_PUBLIC) ; $VERSION = '0.01' ; my $GLOBAL_PRIVATE ; sub Foo { my $this = shift ; my %args = @_ ; @_ = () ; $this->{X} = $args{x} ; $this->{Y} = $args{y} ; } sub x { my $this = shift ; $this->{X} } sub y { my $this = shift ; $this->{Y} } sub test_args { my $this = shift ; my $x = shift(@_) ; my $y = shift(@_) ; my %opts = ref($_[0]) eq 'HASH' ? %{ shift(@_) } : ( ref($_[0]) eq + 'ARRAY' ? @{ shift(@_) } : shift(@_) ) ; my @list = ref($_[0]) eq 'ARRAY' ? @{ shift(@_) } : ( ref($_[0]) e +q 'HASH' ? %{ shift(@_) } : shift(@_) ) ; my $more = shift(@_) ; print ">> $x\n" ; print ">> $y\n" ; my @keys = map { $_ => 1 } (keys %opts , @list) ; print ">> $more\n" ; } sub old_style { my $this = shift ; my ( $x , $y ) = @_ ; print ">> $x , $y\n" ; } sub test_html_block { my $this = shift ; print CLASS_HPLOO_HTML('_foo',( $this->x , $this->y )) ; } $CLASS_HPLOO_HTML{'_foo'} = [ q`my $x = shift(@_) ;my $y = shift(@_) ; +` , <<'CLASS_HPLOO_HTML' ]; <hr> X: $x , Y: $y <hr> CLASS_HPLOO_HTML } 1;

The best thing is to handle automatically the arguments of the method, specially when you want HASH or ARRAY references, what cut off some hard code.

I also use this to introduce Perl developers that don't know very well OO in Perl, but know in Java, to the OO development, since everything that we develope need to be in OO style.

Graciliano M. P.
"Creativity is the expression of the liberty".

janitored by ybiC: Balanced <p><readmore> tags around codeblocks, closed unbalanced <p> tags to facilitate sane janitoring


In reply to How about class Foo {...} definition for Perl? 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.