class
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 2607
Class::CGI 0.20
Class::CGI is a Perl module to fetch objects from your CGI object. more>>
Class::CGI is a Perl module to fetch objects from your CGI object.
SYNOPSIS
use Class::CGI
handlers => {
customer_id => My::Customer::Handler
};
my $cgi = Class::CGI->new;
my $customer = $cgi->param(customer_id);
my $name = $customer->name;
my $email = $cgi->param(email); # behaves like normal
if ( my %errors = $cgi->errors ) {
# do error handling
}
For small CGI scripts, its common to get a parameter, untaint it, pass it to an object constructor and get the object back. This module would allow one to to build Class::CGI handler classes which take the parameter value, automatically perform those steps and just return the object. Much grunt work goes away and you can get back to merely pretending to work.
<<lessSYNOPSIS
use Class::CGI
handlers => {
customer_id => My::Customer::Handler
};
my $cgi = Class::CGI->new;
my $customer = $cgi->param(customer_id);
my $name = $customer->name;
my $email = $cgi->param(email); # behaves like normal
if ( my %errors = $cgi->errors ) {
# do error handling
}
For small CGI scripts, its common to get a parameter, untaint it, pass it to an object constructor and get the object back. This module would allow one to to build Class::CGI handler classes which take the parameter value, automatically perform those steps and just return the object. Much grunt work goes away and you can get back to merely pretending to work.
Download (0.017MB)
Added: 2006-10-20 License: Perl Artistic License Price:
1099 downloads
Class::XML 0.06
Class::XML is a Perl module for simple XML Abstraction. more>>
Class::XML is a Perl module for simple XML Abstraction.
SYNOPSIS
package Foo;
use base qw/Class::XML/;
__PACKAGE__->has_attributes(qw/length colour/);
__PACKAGE__->has_child(bar => Bar);
package Bar;
use base qw/Class::XML/;
__PACKAGE__->has_parent(foo);
__PACKAGE__->has_attribute(counter);
# Meanwhile, in another piece of code -
my $foo = Foo->new( xml => # Or filename or ioref or parser
qq!< foo length="3m" colour="pink" >< bar / >< /foo >! );
$foo->length; # Returns "3m"
$foo->colour("purple"); # Sets colour to purple
print $foo; # Outputs
my $new_bar = new Bar; # Creates empty Bar node
$new_bar->counter("formica");
$foo->bar($new_bar); # Replaces child
$new_bar->foo->colour; # Returns "purple"
$foo->colour(undef); # Deletes colour attribute
print $foo; # Outputs < foo length="3m" >< bar counter="formica" / >< /foo >
Class::XML is designed to make it reasonably easy to create, consume or modify XML from Perl while thinking in terms of Perl objects rather than the available XML APIs; it was written out of a mixture of frustration that JAXB (for Java) and XMLSerializer (for .Net) provided programming capabilities that simply werent easy to do in Perl with the existing modules, and the sheer pleasure that Ive had using Class::DBI.
The aim is to provide a convenient abstraction layer that allows you to put as much of your logic as you like into methods on a class tree, then throw some XML at that tree and get back a tree of objects to work with. It should also be easy to get started with for anybody familiar with Class::DBI (although I doubt you could simply switch them due to the impedance mismatch between XML and relational data) and be pleasant to use from the Template Toolkit.
Finally, all Class::XML objects are also XML::XPath nodes so the full power of XPath is available to you if Class::XML doesnt provide a shortcut to what youre trying to do (but if you find it doesnt on a regular basis, contact me and Ill see if I can fix that.
<<lessSYNOPSIS
package Foo;
use base qw/Class::XML/;
__PACKAGE__->has_attributes(qw/length colour/);
__PACKAGE__->has_child(bar => Bar);
package Bar;
use base qw/Class::XML/;
__PACKAGE__->has_parent(foo);
__PACKAGE__->has_attribute(counter);
# Meanwhile, in another piece of code -
my $foo = Foo->new( xml => # Or filename or ioref or parser
qq!< foo length="3m" colour="pink" >< bar / >< /foo >! );
$foo->length; # Returns "3m"
$foo->colour("purple"); # Sets colour to purple
print $foo; # Outputs
my $new_bar = new Bar; # Creates empty Bar node
$new_bar->counter("formica");
$foo->bar($new_bar); # Replaces child
$new_bar->foo->colour; # Returns "purple"
$foo->colour(undef); # Deletes colour attribute
print $foo; # Outputs < foo length="3m" >< bar counter="formica" / >< /foo >
Class::XML is designed to make it reasonably easy to create, consume or modify XML from Perl while thinking in terms of Perl objects rather than the available XML APIs; it was written out of a mixture of frustration that JAXB (for Java) and XMLSerializer (for .Net) provided programming capabilities that simply werent easy to do in Perl with the existing modules, and the sheer pleasure that Ive had using Class::DBI.
The aim is to provide a convenient abstraction layer that allows you to put as much of your logic as you like into methods on a class tree, then throw some XML at that tree and get back a tree of objects to work with. It should also be easy to get started with for anybody familiar with Class::DBI (although I doubt you could simply switch them due to the impedance mismatch between XML and relational data) and be pleasant to use from the Template Toolkit.
Finally, all Class::XML objects are also XML::XPath nodes so the full power of XPath is available to you if Class::XML doesnt provide a shortcut to what youre trying to do (but if you find it doesnt on a regular basis, contact me and Ill see if I can fix that.
Download (0.018MB)
Added: 2006-09-07 License: Perl Artistic License Price:
1142 downloads
Class::MOP 0.35
Class::MOP is a Meta Object Protocol for Perl 5. more>>
Class::MOP is a Meta Object Protocol for Perl 5.
SYNOPSIS
# ... This will come later, for now see
# the other SYNOPSIS for more information
This module is an attempt to create a meta object protocol for the Perl 5 object system. It makes no attempt to change the behavior or characteristics of the Perl 5 object system, only to create a protocol for its manipulation and introspection.
That said, it does attempt to create the tools for building a rich set of extensions to the Perl 5 object system. Every attempt has been made for these tools to keep to the spirit of the Perl 5 object system that we all know and love.
This documentation is admittedly sparse on details, as time permits I will try to improve them. For now, I suggest looking at the items listed in the "SEE ALSO" section for more information. In particular the book "The Art of the Meta Object Protocol" was very influential in the development of this system.
What is a Meta Object Protocol?
A meta object protocol is an API to an object system.
To be more specific, it is a set of abstractions of the components of an object system (typically things like; classes, object, methods, object attributes, etc.). These abstractions can then be used to both inspect and manipulate the object system which they describe.
It can be said that there are two MOPs for any object system; the implicit MOP, and the explicit MOP. The implicit MOP handles things like method dispatch or inheritance, which happen automatically as part of how the object system works. The explicit MOP typically handles the introspection/reflection features of the object system. All object systems have implicit MOPs, without one, they would not work. Explict MOPs however as less common, and depending on the language can vary from restrictive (Reflection in Java or C#) to wide open (CLOS is a perfect example).
<<lessSYNOPSIS
# ... This will come later, for now see
# the other SYNOPSIS for more information
This module is an attempt to create a meta object protocol for the Perl 5 object system. It makes no attempt to change the behavior or characteristics of the Perl 5 object system, only to create a protocol for its manipulation and introspection.
That said, it does attempt to create the tools for building a rich set of extensions to the Perl 5 object system. Every attempt has been made for these tools to keep to the spirit of the Perl 5 object system that we all know and love.
This documentation is admittedly sparse on details, as time permits I will try to improve them. For now, I suggest looking at the items listed in the "SEE ALSO" section for more information. In particular the book "The Art of the Meta Object Protocol" was very influential in the development of this system.
What is a Meta Object Protocol?
A meta object protocol is an API to an object system.
To be more specific, it is a set of abstractions of the components of an object system (typically things like; classes, object, methods, object attributes, etc.). These abstractions can then be used to both inspect and manipulate the object system which they describe.
It can be said that there are two MOPs for any object system; the implicit MOP, and the explicit MOP. The implicit MOP handles things like method dispatch or inheritance, which happen automatically as part of how the object system works. The explicit MOP typically handles the introspection/reflection features of the object system. All object systems have implicit MOPs, without one, they would not work. Explict MOPs however as less common, and depending on the language can vary from restrictive (Reflection in Java or C#) to wide open (CLOS is a perfect example).
Download (0.072MB)
Added: 2006-10-20 License: Perl Artistic License Price:
1099 downloads
Class::Meta 0.53
Class::Meta is a Perl class automation, introspection, and data validation. more>>
Class::Meta is a Perl class automation, introspection, and data validation.
SYNOPSIS
Generate a class:
package MyApp::Thingy;
use strict;
use Class::Meta;
use Class::Meta::Types::String;
use Class::Meta::Types::Numeric;
BEGIN {
# Create a Class::Meta object for this class.
my $cm = Class::Meta->new( key => thingy );
# Add a constructor.
$cm->add_constructor(
name => new,
create => 1,
);
# Add a couple of attributes with generated methods.
$cm->add_attribute(
name => uuid,
authz => Class::Meta::READ,
type => string,
required => 1,
default => sub { Data::UUID->new->create_str },
);
$cm->add_attribute(
name => name,
is => string,
required => 1,
default => undef,
);
$cm->add_attribute(
name => age,
is => integer,
default => undef,
);
# Add a custom method.
$cm->add_method(
name => chk_pass,
view => Class::Meta::PUBLIC,
);
$cm->build;
}
Then use the class:
use MyApp::Thingy;
my $thingy = MyApp::Thingy->new;
print "ID: ", $thingy->id, $/;
$thingy->name(Larry);
print "Name: ", $thingy->name, $/;
$thingy->age(42);
print "Age: ", $thingy->age, $/;
Or make use of the introspection API:
use MyApp::Thingy;
my $class = MyApp::Thingy->my_class;
my $thingy;
print "Examining object of class ", $class->package, $/;
print "nConstructors:n";
for my $ctor ($class->constructors) {
print " o ", $ctor->name, $/;
$thingy = $ctor->call($class->package);
}
print "nAttributes:n";
for my $attr ($class->attributes) {
print " o ", $attr->name, " => ", $attr->get($thingy), $/;
if ($attr->authz >= Class::Meta::SET && $attr->type eq string) {
$attr->get($thingy, hey there!);
print " Changed to: ", $attr->get($thingy), $/;
}
}
print "nMethods:n";
for my $meth ($class->methods) {
print " o ", $meth->name, $/;
$meth->call($thingy);
}
Class::Meta provides an interface for automating the creation of Perl classes with attribute data type validation. It differs from other such modules in that it includes an introspection API that can be used as a unified interface for all Class::Meta-generated classes. In this sense, it is an implementation of the "Facade" design pattern.
<<lessSYNOPSIS
Generate a class:
package MyApp::Thingy;
use strict;
use Class::Meta;
use Class::Meta::Types::String;
use Class::Meta::Types::Numeric;
BEGIN {
# Create a Class::Meta object for this class.
my $cm = Class::Meta->new( key => thingy );
# Add a constructor.
$cm->add_constructor(
name => new,
create => 1,
);
# Add a couple of attributes with generated methods.
$cm->add_attribute(
name => uuid,
authz => Class::Meta::READ,
type => string,
required => 1,
default => sub { Data::UUID->new->create_str },
);
$cm->add_attribute(
name => name,
is => string,
required => 1,
default => undef,
);
$cm->add_attribute(
name => age,
is => integer,
default => undef,
);
# Add a custom method.
$cm->add_method(
name => chk_pass,
view => Class::Meta::PUBLIC,
);
$cm->build;
}
Then use the class:
use MyApp::Thingy;
my $thingy = MyApp::Thingy->new;
print "ID: ", $thingy->id, $/;
$thingy->name(Larry);
print "Name: ", $thingy->name, $/;
$thingy->age(42);
print "Age: ", $thingy->age, $/;
Or make use of the introspection API:
use MyApp::Thingy;
my $class = MyApp::Thingy->my_class;
my $thingy;
print "Examining object of class ", $class->package, $/;
print "nConstructors:n";
for my $ctor ($class->constructors) {
print " o ", $ctor->name, $/;
$thingy = $ctor->call($class->package);
}
print "nAttributes:n";
for my $attr ($class->attributes) {
print " o ", $attr->name, " => ", $attr->get($thingy), $/;
if ($attr->authz >= Class::Meta::SET && $attr->type eq string) {
$attr->get($thingy, hey there!);
print " Changed to: ", $attr->get($thingy), $/;
}
}
print "nMethods:n";
for my $meth ($class->methods) {
print " o ", $meth->name, $/;
$meth->call($thingy);
}
Class::Meta provides an interface for automating the creation of Perl classes with attribute data type validation. It differs from other such modules in that it includes an introspection API that can be used as a unified interface for all Class::Meta-generated classes. In this sense, it is an implementation of the "Facade" design pattern.
Download (0.060MB)
Added: 2006-10-05 License: Perl Artistic License Price:
1114 downloads
Class::Std 0.0.8
Class::Std is a Perl module to support for creating standard inside-out classes. more>>
Class::Std is a Perl module to support for creating standard "inside-out" classes.
SYNOPSIS
package MyClass;
use Class::Std;
# Create storage for object attributes...
my %name : ATTR;
my %rank : ATTR;
my %snum : ATTR;
my %public_data : ATTR;
# Handle initialization of objects of this class...
sub BUILD {
my ($self, $obj_ID, $arg_ref) = @_;
$name{$obj_ID} = check_name( $arg_ref->{name} );
$rank{$obj_ID} = check_rank( $arg_ref->{rank} );
$snum{$obj_ID} = _gen_uniq_serial_num();
}
# Handle cleanup of objects of this class...
sub DEMOLISH {
my ($self, $obj_ID) = @_;
_recycle_serial_num( $snum{$obj_ID} );
}
# Handle unknown method calls...
sub AUTOMETHOD {
my ($self, $obj_ID, @other_args) = @_;
# Return any public data...
if ( m/A get_(.*)/ ) { # Method name passed in $_
my $get_what = $1;
return sub {
return $public_data{$obj_ID}{$get_what};
}
}
warn "Cant call $method_name on ", ref $self, " object";
return; # The call is declined by not returning a sub ref
}
This module provides tools that help to implement the "inside out object" class structure in a convenient and standard way.
<<lessSYNOPSIS
package MyClass;
use Class::Std;
# Create storage for object attributes...
my %name : ATTR;
my %rank : ATTR;
my %snum : ATTR;
my %public_data : ATTR;
# Handle initialization of objects of this class...
sub BUILD {
my ($self, $obj_ID, $arg_ref) = @_;
$name{$obj_ID} = check_name( $arg_ref->{name} );
$rank{$obj_ID} = check_rank( $arg_ref->{rank} );
$snum{$obj_ID} = _gen_uniq_serial_num();
}
# Handle cleanup of objects of this class...
sub DEMOLISH {
my ($self, $obj_ID) = @_;
_recycle_serial_num( $snum{$obj_ID} );
}
# Handle unknown method calls...
sub AUTOMETHOD {
my ($self, $obj_ID, @other_args) = @_;
# Return any public data...
if ( m/A get_(.*)/ ) { # Method name passed in $_
my $get_what = $1;
return sub {
return $public_data{$obj_ID}{$get_what};
}
}
warn "Cant call $method_name on ", ref $self, " object";
return; # The call is declined by not returning a sub ref
}
This module provides tools that help to implement the "inside out object" class structure in a convenient and standard way.
Download (0.030MB)
Added: 2006-09-26 License: Perl Artistic License Price:
1124 downloads
Class::Inner 0.1
Class::Inner is a perlish implementation of Java like inner classes. more>>
Class::Inner is a perlish implementation of Java like inner classes.
SYNOPSIS
use Class::Inner;
my $object = Class::Inner->new(
parent => ParentClass,
methods => { method => sub { ... } }, },
constructor => new,
args => [@constructor_args],
);
Yet another implementation of an anonymous class with per object overrideable methods, but with the added attraction of sort of working dispatch to the parent classs method.
METHODS
new HASH
Takes a hash like argument list with the following keys.
parent
The name of the parent class. Note that you can only get single inheritance with this or SUPER wont work.
methods
A hash, keys are method names, values are CODEREFs.
constructor
The name of the constructor method. Defaults to new.
args
An anonymous array of arguments to pass to the constructor. Defaults to an empty list.
Returns an object in an anonymous class which inherits from the parent class. This anonymous class has a couple of extra methods:
SUPER
If you were to pass something like
$obj = Class::Inner->new(
parent => Parent,
methods => { method => sub { ...; $self->SUPER::method(@_) } },
);
then $self-gtSUPER::method almost certainly wouldnt do what you expect, so we provide the SUPER method which dispatches to the parent implementation of the current method. There seems to be no good way of getting the full SUPER:: functionality, but Im working on it.
DESTROY
Because Class::Inner works by creating a whole new class name for your object, it could potentially leak memory if you create a lot of them. So we add a DESTROY method that removes the class from the symbol table once its finished with.
If you need to override a parents DESTROY method, adding a call to Class::Inner::clean_symbol_table(ref $self) to it. Do it at the end of the method or your other method calls wont work.
clean_symbol_table
The helper subroutine that DESTROY uses to remove the class from the symbol table.
new_classname
Returns a name for the next anonymous class.
<<lessSYNOPSIS
use Class::Inner;
my $object = Class::Inner->new(
parent => ParentClass,
methods => { method => sub { ... } }, },
constructor => new,
args => [@constructor_args],
);
Yet another implementation of an anonymous class with per object overrideable methods, but with the added attraction of sort of working dispatch to the parent classs method.
METHODS
new HASH
Takes a hash like argument list with the following keys.
parent
The name of the parent class. Note that you can only get single inheritance with this or SUPER wont work.
methods
A hash, keys are method names, values are CODEREFs.
constructor
The name of the constructor method. Defaults to new.
args
An anonymous array of arguments to pass to the constructor. Defaults to an empty list.
Returns an object in an anonymous class which inherits from the parent class. This anonymous class has a couple of extra methods:
SUPER
If you were to pass something like
$obj = Class::Inner->new(
parent => Parent,
methods => { method => sub { ...; $self->SUPER::method(@_) } },
);
then $self-gtSUPER::method almost certainly wouldnt do what you expect, so we provide the SUPER method which dispatches to the parent implementation of the current method. There seems to be no good way of getting the full SUPER:: functionality, but Im working on it.
DESTROY
Because Class::Inner works by creating a whole new class name for your object, it could potentially leak memory if you create a lot of them. So we add a DESTROY method that removes the class from the symbol table once its finished with.
If you need to override a parents DESTROY method, adding a call to Class::Inner::clean_symbol_table(ref $self) to it. Do it at the end of the method or your other method calls wont work.
clean_symbol_table
The helper subroutine that DESTROY uses to remove the class from the symbol table.
new_classname
Returns a name for the next anonymous class.
Download (0.003MB)
Added: 2007-06-06 License: Perl Artistic License Price:
871 downloads
Class::Bits 0.05
Class::Bits is a Perl module with class wrappers around bit vectors. more>>
Class::Bits is a Perl module with class wrappers around bit vectors.
SYNOPSIS
package MyClass;
use Class::Bits;
make_bits( a => 4, # 0..15
b => 1, # 0..1
c => 1, # 0..1
d => 2, # 0..3
e => s4 # -8..7
f => s1 # -1..0
);
package;
$o=MyClass->new(a=>12, d=>2);
print "o->b is ", $o->b, "n";
print "bit vector is ", unpack("h*", $$o), "n";
$o2=$o->new();
$o3=MyClass->new($string);
ABSTRACT
Class::Bits creates class wrappers around bit vectors.
Class::Bits defines classes using bit vectors as storage.
Object attributes are stored in bit fields inside the bit vector. Bit field sizes have to be powers of 2 (1, 2, 4, 8, 16 or 32).
There is a class constructor subroutine:
make_bits( field1 => size1, field2 => size2, ...)
exports in the calling package a ctor, accessor methods, some utility methods and some constants:
Sizes can be prefixed by s or u to define signedness of the field. Default is unsigned.
$class->new()
creates a new object with all zeros.
$class->new($bitvector)
creates a new object over $bitvector.
$class->new(%fields)
creates a new object and initializes its fields with the values in %fields.
$obj->new()
clones an object.
$obj->$field()
$obj->$field($value)
gets or sets the value of the bit field $field inside the bit vector.
$class->length
$obj->lenght
returns the size in bits of the bit vector used for storage.
$class->keys
$obj->keys
returns an array with the names of the object attributes
$obj->as_hash
returns a flatten hash with the object attributes, i.e.:
my %values=$obj->as_hash;
%INDEX
hash with offsets as used by vec perl operator (to get an offset in bits, the value has to be multiplied by the corresponding bit field size).
%SIZES
hash with bit field sizes in bits.
%SIGNED
hash with signedness of the fields
Bit fields are packed in the bit vector in the order specified as arguments to make_bits.
Bit fields are padded inside the bit vector, i.e. a class created like
make_bits(A=>1, B=>2, C=>1, D=>4, E=>8, F=>16);
will have the layout
AxBBCxxx DDDDxxxx EEEEEEEE xxxxxxxx FFFFFFFF FFFFFFFF
<<lessSYNOPSIS
package MyClass;
use Class::Bits;
make_bits( a => 4, # 0..15
b => 1, # 0..1
c => 1, # 0..1
d => 2, # 0..3
e => s4 # -8..7
f => s1 # -1..0
);
package;
$o=MyClass->new(a=>12, d=>2);
print "o->b is ", $o->b, "n";
print "bit vector is ", unpack("h*", $$o), "n";
$o2=$o->new();
$o3=MyClass->new($string);
ABSTRACT
Class::Bits creates class wrappers around bit vectors.
Class::Bits defines classes using bit vectors as storage.
Object attributes are stored in bit fields inside the bit vector. Bit field sizes have to be powers of 2 (1, 2, 4, 8, 16 or 32).
There is a class constructor subroutine:
make_bits( field1 => size1, field2 => size2, ...)
exports in the calling package a ctor, accessor methods, some utility methods and some constants:
Sizes can be prefixed by s or u to define signedness of the field. Default is unsigned.
$class->new()
creates a new object with all zeros.
$class->new($bitvector)
creates a new object over $bitvector.
$class->new(%fields)
creates a new object and initializes its fields with the values in %fields.
$obj->new()
clones an object.
$obj->$field()
$obj->$field($value)
gets or sets the value of the bit field $field inside the bit vector.
$class->length
$obj->lenght
returns the size in bits of the bit vector used for storage.
$class->keys
$obj->keys
returns an array with the names of the object attributes
$obj->as_hash
returns a flatten hash with the object attributes, i.e.:
my %values=$obj->as_hash;
%INDEX
hash with offsets as used by vec perl operator (to get an offset in bits, the value has to be multiplied by the corresponding bit field size).
%SIZES
hash with bit field sizes in bits.
%SIGNED
hash with signedness of the fields
Bit fields are packed in the bit vector in the order specified as arguments to make_bits.
Bit fields are padded inside the bit vector, i.e. a class created like
make_bits(A=>1, B=>2, C=>1, D=>4, E=>8, F=>16);
will have the layout
AxBBCxxx DDDDxxxx EEEEEEEE xxxxxxxx FFFFFFFF FFFFFFFF
Download (0.004MB)
Added: 2007-07-30 License: Perl Artistic License Price:
816 downloads
Test::Class 0.24
Test::Class is a Perl module that allows you to easily create test classes in an xUnit/JUnit style. more>>
Test::Class is a Perl module that allows you to easily create test classes in an xUnit/JUnit style.
SYNOPSIS
package Example::Test;
use base qw(Test::Class);
use Test::More;
# setup methods are run before every test method.
sub make_fixture : Test(setup) {
my $array = [1, 2];
shift->{test_array} = $array;
};
# a test method that runs 1 test
sub test_push : Test {
my $array = shift->{test_array};
push @$array, 3;
is_deeply($array, [1, 2, 3], push worked);
};
# a test method that runs 4 tests
sub test_pop : Test(4) {
my $array = shift->{test_array};
is(pop @$array, 2, pop = 2);
is(pop @$array, 1, pop = 1);
is_deeply($array, [], array empty);
is(pop @$array, undef, pop = undef);
};
# teardown methods are run after every test method.
sub teardown : Test(teardown) {
my $array = shift->{test_array};
diag("array = (@$array) after test(s)");
};
later in a nearby .t file
#! /usr/bin/perl
use Example::Test;
# run all the test methods in Example::Test
Test::Class->runtests;
Outputs:
1..5
ok 1 - pop = 2
ok 2 - pop = 1
ok 3 - array empty
ok 4 - pop = undef
# array = () after test(s)
ok 5 - push worked
# array = (1 2 3) after test(s)
<<lessSYNOPSIS
package Example::Test;
use base qw(Test::Class);
use Test::More;
# setup methods are run before every test method.
sub make_fixture : Test(setup) {
my $array = [1, 2];
shift->{test_array} = $array;
};
# a test method that runs 1 test
sub test_push : Test {
my $array = shift->{test_array};
push @$array, 3;
is_deeply($array, [1, 2, 3], push worked);
};
# a test method that runs 4 tests
sub test_pop : Test(4) {
my $array = shift->{test_array};
is(pop @$array, 2, pop = 2);
is(pop @$array, 1, pop = 1);
is_deeply($array, [], array empty);
is(pop @$array, undef, pop = undef);
};
# teardown methods are run after every test method.
sub teardown : Test(teardown) {
my $array = shift->{test_array};
diag("array = (@$array) after test(s)");
};
later in a nearby .t file
#! /usr/bin/perl
use Example::Test;
# run all the test methods in Example::Test
Test::Class->runtests;
Outputs:
1..5
ok 1 - pop = 2
ok 2 - pop = 1
ok 3 - array empty
ok 4 - pop = undef
# array = () after test(s)
ok 5 - push worked
# array = (1 2 3) after test(s)
Download (0.046MB)
Added: 2007-06-13 License: Perl Artistic License Price:
863 downloads
Class::HPLOO 0.23
Class::HPLOO is an easier way to declare classes on Perl, based in the popular class {...} style and ePod. more>>
Class::HPLOO is an easier way to declare classes on Perl, based in the popular class {...} style and ePod.
USAGE
use Class::HPLOO ;
class Foo extends Bar , Baz {
use LWP::Simple qw(get) ; ## import the method get() to this package.
attr ( array foo_list , int age , string name , foo ) ## define attributes.
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 ;
}
sub attributes_example {
$this->set_foo_list(qw(a b c d e f)) ;
my @l = $this->get_foo_list ;
$this->set_age(30) ;
$this->set_name("Joe") ;
$this->set_foo( time() ) ;
print "NAME: ". $this->get_name ."n" ;
print "AGE: ". $this->get_age ."n" ;
print "FOO: ". $this->get_foo ."n" ;
}
}
## 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}) ;
<<lessUSAGE
use Class::HPLOO ;
class Foo extends Bar , Baz {
use LWP::Simple qw(get) ; ## import the method get() to this package.
attr ( array foo_list , int age , string name , foo ) ## define attributes.
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 ;
}
sub attributes_example {
$this->set_foo_list(qw(a b c d e f)) ;
my @l = $this->get_foo_list ;
$this->set_age(30) ;
$this->set_name("Joe") ;
$this->set_foo( time() ) ;
print "NAME: ". $this->get_name ."n" ;
print "AGE: ". $this->get_age ."n" ;
print "FOO: ". $this->get_foo ."n" ;
}
}
## 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}) ;
Download (0.027MB)
Added: 2007-06-09 License: Perl Artistic License Price:
867 downloads
Class::Date 1.1.9
Class::Date provides a date datatype for Perl. more>>
Class::Date is a perl module, which provides a simple date type for perl.
You can create new Class::Date objects with a constructor from different scalar formats, array refs, and hash refs, and then you can easily manipulate it by the builtin "+" and "-" operators (e.g., $date=date([2001,03,15])+3Y 1s). Relative date types also available.
Enhancements:
- This release adds "ampm" and "meridiam" methods.
<<lessYou can create new Class::Date objects with a constructor from different scalar formats, array refs, and hash refs, and then you can easily manipulate it by the builtin "+" and "-" operators (e.g., $date=date([2001,03,15])+3Y 1s). Relative date types also available.
Enhancements:
- This release adds "ampm" and "meridiam" methods.
Download (0.034MB)
Added: 2006-05-15 License: GPL (GNU General Public License) Price:
1257 downloads
Class::Trait 0.21
Class::Trait is a Perl implementation of Traits in Perl. more>>
Class::Trait is a Perl implementation of Traits in Perl.
SYNOPSIS
# to turn on debugging (do this before
# any other traits are loaded)
use Class::Trait debug;
# nothing happens, but the module is loaded
use Class::Trait;
# loads these two traits and flatten them
# into the current package
use Class::Trait qw(TPrintable TComparable);
# loading a trait and performing some
# trait operations (alias, exclude) first
use Class::Trait (
TPrintable => {
alias => { "stringValue" => "strVal" },
exclude => "stringValue",
},
);
# loading two traits and performing
# a trait operation (exclude) on one
# module to avoid method conflicts
use Class::Trait
TComparable => {
# exclude the basic equality method
# from TComparable and use the ones
# in TEquality instead.
exclude => [ "notEqualTo", "equalTo" ]
},
TEquality #<<less
SYNOPSIS
# to turn on debugging (do this before
# any other traits are loaded)
use Class::Trait debug;
# nothing happens, but the module is loaded
use Class::Trait;
# loads these two traits and flatten them
# into the current package
use Class::Trait qw(TPrintable TComparable);
# loading a trait and performing some
# trait operations (alias, exclude) first
use Class::Trait (
TPrintable => {
alias => { "stringValue" => "strVal" },
exclude => "stringValue",
},
);
# loading two traits and performing
# a trait operation (exclude) on one
# module to avoid method conflicts
use Class::Trait
TComparable => {
# exclude the basic equality method
# from TComparable and use the ones
# in TEquality instead.
exclude => [ "notEqualTo", "equalTo" ]
},
TEquality #<<less
Download (0.033MB)
Added: 2006-10-05 License: Perl Artistic License Price:
1114 downloads
PHP Profiler Class
PHP Profiler Class is a PHP code profiler to aid in performance optimisation. more>>
This profiler is intended to be used to identify areas of code that could be optimised in order to improve overall performance of an application. Typically I identify the areas of concern in an application and place profile timers around those sections and focus down to add timers around the areas that are taking the most time and look for ways to optimise those particular areas.
The items with the highest percentage time spent are usually the ones that can give the biggest improvements.
PHP Class to perform code profiling in order to aid locating areas of code that consume most processing time.
Provides information on number of calls to a code section, percentage and total of time spent on a section. Timing of nested code sections is possible.
Main features:
- Count the number of times a section of code is executed
- Calculate the total ammount of time spent executing a section of code
- Permit multiple timers to be set
- Allow nested timers to such that the parent timers are suspended whilst a child section of code is running.
- Output a report at the end of execution to show the percentage of time spent on an operation,
- the number of times the section was run, the overall time spent on the section.
Usage:
# include_once( profiler.inc);
$prof = new Profiler( profile_flag, trace_flag );
# Profile_flag = true enables output of the statistical information
# trace_flag = true enables output of the trace information
$prof->startTimer( "timer_name", "Description" );
# timer_name is a simple string to name the timer
# description is an optional string to describe the purpose of the timer in more detail
$prof->stopTimer( "timer_name" );
$prof->printTimers( flag );
Output the final report of the processing operation being run. Normally this would be called as one of the last statements on a page.
If flag=true is set then the output will be forced even if the profile_flag was set false when the profiler was initialised
<<lessThe items with the highest percentage time spent are usually the ones that can give the biggest improvements.
PHP Class to perform code profiling in order to aid locating areas of code that consume most processing time.
Provides information on number of calls to a code section, percentage and total of time spent on a section. Timing of nested code sections is possible.
Main features:
- Count the number of times a section of code is executed
- Calculate the total ammount of time spent executing a section of code
- Permit multiple timers to be set
- Allow nested timers to such that the parent timers are suspended whilst a child section of code is running.
- Output a report at the end of execution to show the percentage of time spent on an operation,
- the number of times the section was run, the overall time spent on the section.
Usage:
# include_once( profiler.inc);
$prof = new Profiler( profile_flag, trace_flag );
# Profile_flag = true enables output of the statistical information
# trace_flag = true enables output of the trace information
$prof->startTimer( "timer_name", "Description" );
# timer_name is a simple string to name the timer
# description is an optional string to describe the purpose of the timer in more detail
$prof->stopTimer( "timer_name" );
$prof->printTimers( flag );
Output the final report of the processing operation being run. Normally this would be called as one of the last statements on a page.
If flag=true is set then the output will be forced even if the profile_flag was set false when the profiler was initialised
Download (0.004MB)
Added: 2005-04-12 License: GPL (GNU General Public License) Price:
1661 downloads
DB_cart Class 1.13
DB_cart Class is a MySQL shopping cart script that can be used with third party product catalogues and membership systems. more>>
DB_cart Class is a MySQL shopping cart script that can be used with third party product catalogues and membership systems. The MySQL database structure is neutral to existing systems.
DB_cart Class can handle the shopping cart (add, update, and empty) and checkout process (set the shipment address and email the order).
For existing cart users, the shopping cart is still available upon the users next visit and is visible by checkout. The last option is configurable togther with a time period.
Enhancements:
- There are modifications and improvements inside the main class file, several examples, and the table structure has been extended.
- There two additional fields for the shipment values (name2 and address2).
- All messages are available in German, English, and Dutch.
- The standard text inside the email messages is in external files now; this content is parsed inside the improved email method.
<<lessDB_cart Class can handle the shopping cart (add, update, and empty) and checkout process (set the shipment address and email the order).
For existing cart users, the shopping cart is still available upon the users next visit and is visible by checkout. The last option is configurable togther with a time period.
Enhancements:
- There are modifications and improvements inside the main class file, several examples, and the table structure has been extended.
- There two additional fields for the shipment values (name2 and address2).
- All messages are available in German, English, and Dutch.
- The standard text inside the email messages is in external files now; this content is parsed inside the improved email method.
Download (0.035MB)
Added: 2006-06-16 License: BSD License Price:
1227 downloads
Class::Spiffy 0.15
Class::Spiffy is a Spiffy Framework with No Source Filtering. more>>
Class::Spiffy is a Spiffy Framework with No Source Filtering.
SYNOPSIS
package Keen;
use strict;
use warnings;
use Class::Spiffy -base;
field mirth;
const mood => :-);
sub happy {
my $self = shift;
if ($self->mood eq :-() {
$self->mirth(-1);
print "Cheer up!";
}
super;
}
1;
"Class::Spiffy" is a framework and methodology for doing object oriented (OO) programming in Perl. Class::Spiffy combines the best parts of Exporter.pm, base.pm, mixin.pm and SUPER.pm into one magic foundation class. It attempts to fix all the nits and warts of traditional Perl OO, in a clean, straightforward and (perhaps someday) standard way.
Class::Spiffy borrows ideas from other OO languages like Python, Ruby, Java and Perl 6. It also adds a few tricks of its own.
If you take a look on CPAN, there are a ton of OO related modules. When starting a new project, you need to pick the set of modules that makes most sense, and then you need to use those modules in each of your classes. Class::Spiffy, on the other hand, has everything youll probably need in one module, and you only need to use it once in one of your classes. If you make Class::Spiffy the base class of the basest class in your project, Class::Spiffy will automatically pass all of its magic to all of your subclasses. You may eventually forget that youre even using it!
The most striking difference between Class::Spiffy and other Perl object oriented base classes, is that it has the ability to export things. If you create a subclass of Class::Spiffy, all the things that Class::Spiffy exports will automatically be exported by your subclass, in addition to any more things that you want to export. And if someone creates a subclass of your subclass, all of those things will be exported automatically, and so on. Think of it as "Inherited Exportation", and it uses the familiar Exporter.pm specification syntax.
To use Class::Spiffy or any subclass of Class::Spiffy as a base class of your class, you specify the -base argument to the use command.
use MySpiffyBaseModule -base;
You can also use the traditional use base MySpiffyBaseModule; syntax and everything will work exactly the same. The only caveat is that Class::Spiffy must already be loaded. Thats because Class::Spiffy rewires base.pm on the fly to do all the Spiffy magics.
Class::Spiffy has support for Ruby-like mixins with Perl6-like roles. Just like base you can use either of the following invocations:
use mixin MySpiffyBaseModule;
use MySpiffyBaseModule -mixin;
The second version will only work if the class being mixed in is a subclass of Class::Spiffy. The first version will work in all cases, as long as Class::Spiffy has already been loaded.
To limit the methods that get mixed in, use roles. (Hint: they work just like an Exporter list):
use MySpiffyBaseModule -mixin => qw(:basics x y !foo);
A useful feature of Class::Spiffy is that it exports two functions: field and const that can be used to declare the attributes of your class, and automatically generate accessor methods for them. The only difference between the two functions is that const attributes can not be modified; thus the accessor is much faster.
One interesting aspect of OO programming is when a method calls the same method from a parent class. This is generally known as calling a super method. Perls facility for doing this is butt ugly:
sub cleanup {
my $self = shift;
$self->scrub;
$self->SUPER::cleanup(@_);
}
Class::Spiffy makes it, er, super easy to call super methods. You just use the super function. You dont need to pass it any arguments because it automatically passes them on for you. Heres the same function with Class::Spiffy:
sub cleanup {
my $self = shift;
$self->scrub;
super;
}
Class::Spiffy has a special method for parsing arguments called parse_arguments, that it also uses for parsing its own arguments. You declare which arguments are boolean (singletons) and which ones are paired, with two special methods called boolean_arguments and paired_arguments. Parse arguments pulls out the booleans and pairs and returns them in an anonymous hash, followed by a list of the unmatched arguments.
Finally, Class::Spiffy can export a few debugging functions WWW, XXX, YYY and ZZZ. Each of them produces a YAML dump of its arguments. WWW warns the output, XXX dies with the output, YYY prints the output, and ZZZ confesses the output. If YAML doesnt suit your needs, you can switch all the dumps to Data::Dumper format with the - dumper option.
<<lessSYNOPSIS
package Keen;
use strict;
use warnings;
use Class::Spiffy -base;
field mirth;
const mood => :-);
sub happy {
my $self = shift;
if ($self->mood eq :-() {
$self->mirth(-1);
print "Cheer up!";
}
super;
}
1;
"Class::Spiffy" is a framework and methodology for doing object oriented (OO) programming in Perl. Class::Spiffy combines the best parts of Exporter.pm, base.pm, mixin.pm and SUPER.pm into one magic foundation class. It attempts to fix all the nits and warts of traditional Perl OO, in a clean, straightforward and (perhaps someday) standard way.
Class::Spiffy borrows ideas from other OO languages like Python, Ruby, Java and Perl 6. It also adds a few tricks of its own.
If you take a look on CPAN, there are a ton of OO related modules. When starting a new project, you need to pick the set of modules that makes most sense, and then you need to use those modules in each of your classes. Class::Spiffy, on the other hand, has everything youll probably need in one module, and you only need to use it once in one of your classes. If you make Class::Spiffy the base class of the basest class in your project, Class::Spiffy will automatically pass all of its magic to all of your subclasses. You may eventually forget that youre even using it!
The most striking difference between Class::Spiffy and other Perl object oriented base classes, is that it has the ability to export things. If you create a subclass of Class::Spiffy, all the things that Class::Spiffy exports will automatically be exported by your subclass, in addition to any more things that you want to export. And if someone creates a subclass of your subclass, all of those things will be exported automatically, and so on. Think of it as "Inherited Exportation", and it uses the familiar Exporter.pm specification syntax.
To use Class::Spiffy or any subclass of Class::Spiffy as a base class of your class, you specify the -base argument to the use command.
use MySpiffyBaseModule -base;
You can also use the traditional use base MySpiffyBaseModule; syntax and everything will work exactly the same. The only caveat is that Class::Spiffy must already be loaded. Thats because Class::Spiffy rewires base.pm on the fly to do all the Spiffy magics.
Class::Spiffy has support for Ruby-like mixins with Perl6-like roles. Just like base you can use either of the following invocations:
use mixin MySpiffyBaseModule;
use MySpiffyBaseModule -mixin;
The second version will only work if the class being mixed in is a subclass of Class::Spiffy. The first version will work in all cases, as long as Class::Spiffy has already been loaded.
To limit the methods that get mixed in, use roles. (Hint: they work just like an Exporter list):
use MySpiffyBaseModule -mixin => qw(:basics x y !foo);
A useful feature of Class::Spiffy is that it exports two functions: field and const that can be used to declare the attributes of your class, and automatically generate accessor methods for them. The only difference between the two functions is that const attributes can not be modified; thus the accessor is much faster.
One interesting aspect of OO programming is when a method calls the same method from a parent class. This is generally known as calling a super method. Perls facility for doing this is butt ugly:
sub cleanup {
my $self = shift;
$self->scrub;
$self->SUPER::cleanup(@_);
}
Class::Spiffy makes it, er, super easy to call super methods. You just use the super function. You dont need to pass it any arguments because it automatically passes them on for you. Heres the same function with Class::Spiffy:
sub cleanup {
my $self = shift;
$self->scrub;
super;
}
Class::Spiffy has a special method for parsing arguments called parse_arguments, that it also uses for parsing its own arguments. You declare which arguments are boolean (singletons) and which ones are paired, with two special methods called boolean_arguments and paired_arguments. Parse arguments pulls out the booleans and pairs and returns them in an anonymous hash, followed by a list of the unmatched arguments.
Finally, Class::Spiffy can export a few debugging functions WWW, XXX, YYY and ZZZ. Each of them produces a YAML dump of its arguments. WWW warns the output, XXX dies with the output, YYY prints the output, and ZZZ confesses the output. If YAML doesnt suit your needs, you can switch all the dumps to Data::Dumper format with the - dumper option.
Download (0.024MB)
Added: 2007-06-19 License: Perl Artistic License Price:
857 downloads
Class::Simple 0.07
Class::Simple is a simple Object-Oriented Base Class. more>>
Class::Simple is a simple Object-Oriented Base Class.
SYNOPSIS
package Foo:
use base qw(Class::Simple);
BEGIN
{
Foo->privatize(qw(attrib1 attrib2)); # ...or not.
}
my $obj = Foo->new();
$obj->attrib(1); # The same as...
$obj->set_attrib(1); # ...this.
my $var = $obj->get_attrib(); # The same as...
$var = $obj->attrib; # ...this.
$obj->raise_attrib(); # The same as...
$obj->set_attrib(1); # ...this.
$obj->clear_attrib(); # The same as...
$obj->set_attrib(undef); # ...this
$obj->attrib(undef); # ...and this.
$obj->readonly_attrib(4);
sub foo
{
my $self = shift;
my $value = shift;
$self->_foo($value);
do_other_things(@_);
...
}
my $str = $obj->DUMP;
my $new_obj = Foo->new();
$new_obj->SLURP($str);
sub BUILD
{
my $self = shift;
# Various initializations
}
There are plenty of others that are much more thorough and whatnot but sometimes I want something simple so I can get just going (no doubt because I am a simple guy) so I use this.
What do I mean by simple? First off, I dont want to have to list out all my methods beforehand. I just want to use them (Yeah, yeah, it doesnt catch typos--thats what testing and Class::Std are for :-). Next, I want to be able to call my methods by $obj->foo(1) or $obj->set_foo(1), by $obj->foo() or $obj->get_foo(). Dont tell ME I have to use get_ and set_ (I would just override that restriction in Class::Std anyway). Simple!
I did want some neat features, though, so these are inside-out objects (meaning the object isnt simply a hash so you cant just go in and muck with attributes outside of methods), privatization of methods is supported, as is serialization out and back in again.
<<lessSYNOPSIS
package Foo:
use base qw(Class::Simple);
BEGIN
{
Foo->privatize(qw(attrib1 attrib2)); # ...or not.
}
my $obj = Foo->new();
$obj->attrib(1); # The same as...
$obj->set_attrib(1); # ...this.
my $var = $obj->get_attrib(); # The same as...
$var = $obj->attrib; # ...this.
$obj->raise_attrib(); # The same as...
$obj->set_attrib(1); # ...this.
$obj->clear_attrib(); # The same as...
$obj->set_attrib(undef); # ...this
$obj->attrib(undef); # ...and this.
$obj->readonly_attrib(4);
sub foo
{
my $self = shift;
my $value = shift;
$self->_foo($value);
do_other_things(@_);
...
}
my $str = $obj->DUMP;
my $new_obj = Foo->new();
$new_obj->SLURP($str);
sub BUILD
{
my $self = shift;
# Various initializations
}
There are plenty of others that are much more thorough and whatnot but sometimes I want something simple so I can get just going (no doubt because I am a simple guy) so I use this.
What do I mean by simple? First off, I dont want to have to list out all my methods beforehand. I just want to use them (Yeah, yeah, it doesnt catch typos--thats what testing and Class::Std are for :-). Next, I want to be able to call my methods by $obj->foo(1) or $obj->set_foo(1), by $obj->foo() or $obj->get_foo(). Dont tell ME I have to use get_ and set_ (I would just override that restriction in Class::Std anyway). Simple!
I did want some neat features, though, so these are inside-out objects (meaning the object isnt simply a hash so you cant just go in and muck with attributes outside of methods), privatization of methods is supported, as is serialization out and back in again.
Download (0.009MB)
Added: 2007-07-31 License: Perl Artistic License Price:
815 downloads
Secleted [ 0 ] software to compare
Copyright Notice:
Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future software development. The above class search only lists software in full, demo and trial versions for free download. Download links are directly from our mirror sites or publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed