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> %> }
{ 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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |