Re: Possible module for 'safer' signal handling....

2004-01-17 Thread Lincoln A. Baxter
I've just requested registration of and uploaded:
ftp://pause.perl.org/incoming/Sys-SigAction-0.01.tar.gz

Thanks to all who helped in discussing this.

Lincoln





How about class Foo {...} definition for Perl?

2004-01-17 Thread Graciliano M. P.
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.

You can get it at:
http://search.cpan.org/~gmpassos/

But I want to know what the other module author think about it, since this
is a tool for us?

Just some example of syntax:

  use Class::HPLOO ;

  class Foo extends Bar , Baz {

vars ($VERSION , $GLOBAL_PUBLIC) ;

$VERSION = '0.01' ;

my $GLOBAL_PRIVATE ;

## Initializer (called by default new):
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 , [EMAIL PROTECTED] , $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]) eq
'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.

Regards,
Graciliano M. P.