NAME
Class::HPLOO - Easier way to declare classes on Perl, based in the popular class {...} style and ePod.
DESCRIPTION
This is the implemantation of OO-Classes for HPL. This bring a easy way to create PM classes, but with HPL resources/style.
USAGE
class Foo extends Bar , Baz {
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] ;
}
## methods 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 ;
}
## methos 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'}) ;
CONTRUCTOR
The "method" new() is automatically declared by Class::HPLOO, then it calls the initializer that is a method with the name of the class, like Java.
class Foo extends {
## initializer:
sub Foo {
$this->{attr} = $_[0] ;
}
}
** Note that what the initializer returns is ignored! Unless you return a new constructed object or 0. Return 0 makes the creation of the object return undef.
DESTRUCTOR
Use DESTROY() like a normal Perl package.
METHODS
All the methods of the classes are declared like a normal sub.
You can declare the input variables to reaceive the arguments of the method:
sub methodx ($arg1 , $arg2 , \@listref , \%hasref , @rest) {
...
}
## Calling:
$foo->methodx(123 , 456 , [0,1,2] , {k1 => 'x'} , 7 , 8 , 9 ) ;
HTML BLOCKS
You can use HTML blocks in the class like in HPL documents:
class Foo {
sub test {
print <% html_test>(123) ;
}
<% html_test($n)
<hr>
NUMBER: $n
<hr>
%>
}
SUB CLASSES
From version 0.04+ you can declare sub-classes:
class foo {
class subfoo { ... }
}
You also can handle the base name of a class adding "." in the begin of the class name:
class foo {
class .in { ... }
}
The class name .in will be translated to foo::in.
DUMP
You can dump the generated code:
use Class::HPLOO qw(dump nice) ;
** The nice option just try to make a cleaner code.
BUILD
The script "build-hploo.pl" can be used to convert .hploo files .pm files.
Soo, tou can write a Perl Module with Class::HPLOO and release it as a normal .pm file without need Class::HPLOO installed.
If you have ePod (0.03+) installed you can use ePod to write your documentation. For .hploo files the ePod need to be alwasy after __END__.
Note that ePod accepts POD syntax too, soo you still can use normal POD for documentation.
SEE ALSO
AUTHOR
Graciliano M. P. <gm@virtuasites.com.br>
I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 726:
You forgot a '=back' before '=head1'