classes v2
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 2738
classes::Test 0.942
classes::Test are functions to help with classes pragma testing. more>>
classes::Test are functions to help with classes pragma testing.
SYNOPSIS
can_new
can_set_get
has_decl
has_class_const
has_mixins
has_mixins_hash
is_classes MyClass;
is_classes main;
is_throwable X::Mine;
is_classes_exc X::Mine;
Generic tests based on Test::Builder designed to help write unit tests for code that uses the classes pragma.
<<lessSYNOPSIS
can_new
can_set_get
has_decl
has_class_const
has_mixins
has_mixins_hash
is_classes MyClass;
is_classes main;
is_throwable X::Mine;
is_classes_exc X::Mine;
Generic tests based on Test::Builder designed to help write unit tests for code that uses the classes pragma.
Download (0.16MB)
Added: 2006-10-31 License: Perl Artistic License Price:
1088 downloads
Perl6::Classes 0.22
Perl6::Classes project contains first class classes in Perl 5. more>>
Perl6::Classes project contains first class classes in Perl 5.
SYNOPSIS
use Perl6::Classes;
class Composer {
submethod BUILD { print "Giving birth to a new composern" }
method compose { print "Writing some music...n" }
}
class ClassicalComposer is Composer {
method compose { print "Writing some muzak...n" }
}
class ModernComposer is Composer {
submethod BUILD($) { $.length = shift }
method compose() { print((map { int rand 10 } 1..$.length), "n") }
has $.length;
}
my $beethoven = new ClassicalComposer;
my $barber = new ModernComposer 4;
my $mahler = ModernComposer->new(400);
$beethoven->compose; # Writing some muzak...
$barber->compose # 7214
compose $mahler; # 89275869347968374698756....
Perl6::Classes allows the creation of (somewhat) Perl 6-style classes in Perl 5. The following features are currently supported:
subs, methods, and submethods
And their respective scoping rules.
Attributes
Which are available through the has keyword, and look like $.this.
Inheritance
Both single and multiple inheritance are available through the is keyword.
Signatures
Signatures on methods, subs, and submethods are supported, but just the Perl 5 kind.
Data hiding
Using the public, protected, and private traits, you can enforce (run-time) data hiding. This is not supported on attributes, which are always private.
Anonymous classes
That respect closures. You can now nest them inside methods of other classes, even other anonymous ones!
The Perl6::Classes module augments Perls syntax with a new declarator: class. It offers the advantage over Perls standard OO mechanism that it is conceptually easier to see (especially for those from a C++/Java background). It offers the disadvantage, of course, of being less versatile.
<<lessSYNOPSIS
use Perl6::Classes;
class Composer {
submethod BUILD { print "Giving birth to a new composern" }
method compose { print "Writing some music...n" }
}
class ClassicalComposer is Composer {
method compose { print "Writing some muzak...n" }
}
class ModernComposer is Composer {
submethod BUILD($) { $.length = shift }
method compose() { print((map { int rand 10 } 1..$.length), "n") }
has $.length;
}
my $beethoven = new ClassicalComposer;
my $barber = new ModernComposer 4;
my $mahler = ModernComposer->new(400);
$beethoven->compose; # Writing some muzak...
$barber->compose # 7214
compose $mahler; # 89275869347968374698756....
Perl6::Classes allows the creation of (somewhat) Perl 6-style classes in Perl 5. The following features are currently supported:
subs, methods, and submethods
And their respective scoping rules.
Attributes
Which are available through the has keyword, and look like $.this.
Inheritance
Both single and multiple inheritance are available through the is keyword.
Signatures
Signatures on methods, subs, and submethods are supported, but just the Perl 5 kind.
Data hiding
Using the public, protected, and private traits, you can enforce (run-time) data hiding. This is not supported on attributes, which are always private.
Anonymous classes
That respect closures. You can now nest them inside methods of other classes, even other anonymous ones!
The Perl6::Classes module augments Perls syntax with a new declarator: class. It offers the advantage over Perls standard OO mechanism that it is conceptually easier to see (especially for those from a C++/Java background). It offers the disadvantage, of course, of being less versatile.
Download (0.007MB)
Added: 2007-06-08 License: Perl Artistic License Price:
868 downloads
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::Adapter 1.02
Class::Adapter is a Perl implementation of the Adapter Design Pattern. more>>
Class::Adapter is a Perl implementation of the "Adapter" Design Pattern.
The Class::Adapter class is intended as an abstract base class for creating any sort of class or object that follows the Adapter pattern.
What is an Adapter?
The term Adapter refers to a "Design Pattern" of the same name, from the famous "Gang of Four" book "Design Patterns". Although their original implementation was designed for Java and similar single-inheritance strictly-typed langauge, the situation for which it applies is still valid.
An Adapter in this Perl sense of the term is when a class is created to achieve by composition (objects containing other object) something that cant be achieved by inheritance (sub-classing).
This is similar to the Decorator pattern, but is intended to be applied on a class-by-class basis, as opposed to being able to be applied one object at a time, as is the case with the Decorator pattern.
The Class::Adapter object holds a parent object that it "wraps", and when a method is called on the Class::Adapter, it manually calls the same (or different) method with the same (or different) parameters on the parent object contained within it.
Instead of these custom methods being hooked in on an object-by-object basis, they are defined at the class level.
Basically, a Class::Adapter is one of your fall-back positions when Perls inheritance model fails you, or is no longer good enough, and you need to do something twisty in order to make several APIs play nicely with each other.
What can I do with the actual Class::Adapter class
Well... nothing really. It exist to provide some extremely low level fundamental methods, and to provide a common base for inheritance of Adapter classes.
The base Class::Adapter class doesnt even implement a way to push method calls through to the underlying object, since the way in which that happens is the bit that changes from case to case.
To actually DO something, you probably want to go take a look at Class::Adapter::Builder, which makes the creation of Adapter classes relatively quick and easy.
<<lessThe Class::Adapter class is intended as an abstract base class for creating any sort of class or object that follows the Adapter pattern.
What is an Adapter?
The term Adapter refers to a "Design Pattern" of the same name, from the famous "Gang of Four" book "Design Patterns". Although their original implementation was designed for Java and similar single-inheritance strictly-typed langauge, the situation for which it applies is still valid.
An Adapter in this Perl sense of the term is when a class is created to achieve by composition (objects containing other object) something that cant be achieved by inheritance (sub-classing).
This is similar to the Decorator pattern, but is intended to be applied on a class-by-class basis, as opposed to being able to be applied one object at a time, as is the case with the Decorator pattern.
The Class::Adapter object holds a parent object that it "wraps", and when a method is called on the Class::Adapter, it manually calls the same (or different) method with the same (or different) parameters on the parent object contained within it.
Instead of these custom methods being hooked in on an object-by-object basis, they are defined at the class level.
Basically, a Class::Adapter is one of your fall-back positions when Perls inheritance model fails you, or is no longer good enough, and you need to do something twisty in order to make several APIs play nicely with each other.
What can I do with the actual Class::Adapter class
Well... nothing really. It exist to provide some extremely low level fundamental methods, and to provide a common base for inheritance of Adapter classes.
The base Class::Adapter class doesnt even implement a way to push method calls through to the underlying object, since the way in which that happens is the bit that changes from case to case.
To actually DO something, you probably want to go take a look at Class::Adapter::Builder, which makes the creation of Adapter classes relatively quick and easy.
Download (0.024MB)
Added: 2007-06-20 License: Perl Artistic License Price:
856 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
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::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::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
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::Container 0.12
Class::Container is a Perl module with Glues object frameworks together transparently. more>>
Class::Container is a Perl module with Glues object frameworks together transparently.
SYNOPSIS
package Car;
use Class::Container;
@ISA = qw(Class::Container);
__PACKAGE__->valid_params
(
paint => {default => burgundy},
style => {default => coupe},
windshield => {isa => Glass},
radio => {isa => Audio::Device},
);
__PACKAGE__->contained_objects
(
windshield => Glass::Shatterproof,
wheel => { class => Vehicle::Wheel,
delayed => 1 },
radio => Audio::MP3,
);
sub new {
my $package = shift;
# windshield and radio objects are created automatically by
# SUPER::new()
my $self = $package->SUPER::new(@_);
$self->{right_wheel} = $self->create_delayed_object(wheel);
... do any more initialization here ...
return $self;
}
This class facilitates building frameworks of several classes that inter-operate. It was first designed and built for HTML::Mason, in which the Compiler, Lexer, Interpreter, Resolver, Component, Buffer, and several other objects must create each other transparently, passing the appropriate parameters to the right class, possibly substituting other subclasses for any of these objects.
The main features of Class::Container are:
Explicit declaration of containment relationships (aggregation, factory creation, etc.)
Declaration of constructor parameters accepted by each member in a class framework
Transparent passing of constructor parameters to the class that needs them
Ability to create one (automatic) or many (manual) contained objects automatically and transparently
<<lessSYNOPSIS
package Car;
use Class::Container;
@ISA = qw(Class::Container);
__PACKAGE__->valid_params
(
paint => {default => burgundy},
style => {default => coupe},
windshield => {isa => Glass},
radio => {isa => Audio::Device},
);
__PACKAGE__->contained_objects
(
windshield => Glass::Shatterproof,
wheel => { class => Vehicle::Wheel,
delayed => 1 },
radio => Audio::MP3,
);
sub new {
my $package = shift;
# windshield and radio objects are created automatically by
# SUPER::new()
my $self = $package->SUPER::new(@_);
$self->{right_wheel} = $self->create_delayed_object(wheel);
... do any more initialization here ...
return $self;
}
This class facilitates building frameworks of several classes that inter-operate. It was first designed and built for HTML::Mason, in which the Compiler, Lexer, Interpreter, Resolver, Component, Buffer, and several other objects must create each other transparently, passing the appropriate parameters to the right class, possibly substituting other subclasses for any of these objects.
The main features of Class::Container are:
Explicit declaration of containment relationships (aggregation, factory creation, etc.)
Declaration of constructor parameters accepted by each member in a class framework
Transparent passing of constructor parameters to the class that needs them
Ability to create one (automatic) or many (manual) contained objects automatically and transparently
Download (0.019MB)
Added: 2006-10-06 License: Perl Artistic License Price:
1113 downloads
Class::Classless 1.35
Class::Classless is a Perl framework for classless OOP. more>>
Class::Classless is a Perl framework for classless OOP.
SYNOPSIS
use strict;
use Class::Classless;
my $ob1 = $Class::Classless::ROOT->clone;
$ob1->{NAME} = Ob1;
$ob1->{stuff} = 123;
$ob1->{Thing} = 789;
my $ob2 = $ob1->clone;
$ob2->{NAME} = Ob2;
printf "ob1 stuff: n", $ob1->{stuff};
printf "ob2 stuff: n", $ob2->{stuff};
printf "ob1 Thing: n", $ob1->{Thing};
printf "ob2 Thing: n", $ob2->{Thing};
$ob1->{METHODS}{zaz} = sub {
print "Zaz! on ", $_[0]{NAME}, "n";
};
$ob1->zaz;
$ob2->zaz;
$ob1->EXAMINE;
$ob2->EXAMINE;
This prints the following:
ob1 stuff: < 123 >
ob2 stuff: < 123 >
ob1 Thing: < 789 >
ob2 Thing: < >
Zaz! on Ob1
Zaz! on Ob2
< Class::Classless::X=HASH(0x200236f4) >
stuff, 123,
NAME, Ob1,
Thing, 789,
METHODS, { zaz, CODE(0x20068360) },
PARENTS, [ ROOT ],
< Class::Classless::X=HASH(0x2002cb48) >
stuff, 123,
NAME, Ob2,
METHODS, { },
PARENTS, [ Ob1 ],
In class-based OOP frameworks, methods are applicable to objects by virtue of objects belonging to classes that either provide those methods, or inherit them from classes that do.
In classless OOP frameworks (AKA delegation-and-prototypes frameworks), what methods an object is capable of is basically an attribute of that object. That is, in Perl terms: instead of methods being entries in the symbol table of the package/class the object belongs to, they are entries in a hash table inside the object. Inheritance is implemented not by having classes inheriting from other classes (via ISA lists), but by having objects inherit from other objects (via PARENTS lists).
In class-based OOP frameworks, you get new objects by calling constructors. In a classless framework, you get new objects by copying ("cloning") an existing object -- and the new clone becomes a child (inheritor) of the original object. (Where do you get the one original object? The language provides one, which has no parents, and which contains some general purpose methods like "clone".)
<<lessSYNOPSIS
use strict;
use Class::Classless;
my $ob1 = $Class::Classless::ROOT->clone;
$ob1->{NAME} = Ob1;
$ob1->{stuff} = 123;
$ob1->{Thing} = 789;
my $ob2 = $ob1->clone;
$ob2->{NAME} = Ob2;
printf "ob1 stuff: n", $ob1->{stuff};
printf "ob2 stuff: n", $ob2->{stuff};
printf "ob1 Thing: n", $ob1->{Thing};
printf "ob2 Thing: n", $ob2->{Thing};
$ob1->{METHODS}{zaz} = sub {
print "Zaz! on ", $_[0]{NAME}, "n";
};
$ob1->zaz;
$ob2->zaz;
$ob1->EXAMINE;
$ob2->EXAMINE;
This prints the following:
ob1 stuff: < 123 >
ob2 stuff: < 123 >
ob1 Thing: < 789 >
ob2 Thing: < >
Zaz! on Ob1
Zaz! on Ob2
< Class::Classless::X=HASH(0x200236f4) >
stuff, 123,
NAME, Ob1,
Thing, 789,
METHODS, { zaz, CODE(0x20068360) },
PARENTS, [ ROOT ],
< Class::Classless::X=HASH(0x2002cb48) >
stuff, 123,
NAME, Ob2,
METHODS, { },
PARENTS, [ Ob1 ],
In class-based OOP frameworks, methods are applicable to objects by virtue of objects belonging to classes that either provide those methods, or inherit them from classes that do.
In classless OOP frameworks (AKA delegation-and-prototypes frameworks), what methods an object is capable of is basically an attribute of that object. That is, in Perl terms: instead of methods being entries in the symbol table of the package/class the object belongs to, they are entries in a hash table inside the object. Inheritance is implemented not by having classes inheriting from other classes (via ISA lists), but by having objects inherit from other objects (via PARENTS lists).
In class-based OOP frameworks, you get new objects by calling constructors. In a classless framework, you get new objects by copying ("cloning") an existing object -- and the new clone becomes a child (inheritor) of the original object. (Where do you get the one original object? The language provides one, which has no parents, and which contains some general purpose methods like "clone".)
Download (0.023MB)
Added: 2007-07-19 License: Perl Artistic License Price:
827 downloads
Class::Agreement 0.02
Class::Agreement is a Perl module that add contracts to your Perl classes easily. more>>
Class::Agreement is a Perl module that add contracts to your Perl classes easily.
SYNOPSIS
package SomeClass;
use Class::Agreement;
# use base Class::Accessor or Class::MethodMaker,
# or roll your own:
sub new { ... }
invariant {
my ($self) = @_;
$self->count > 0;
};
precondition add_a_positive => sub {
my ( $self, $value ) = @_;
return ( $value >= 0 );
};
sub add_a_positive {
my ( $self, $value ) = @_;
...
}
sub choose_word {
my ( $self, $value ) = @_;
...
}
postcondition choose_word => sub {
return ( result >= 0 );
};
dependent increase_foo => sub {
my ( $self, $amount ) = @_;
my $old_foo = $self->foo;
return sub {
my ( $self, $amount ) = @_;
return ( $old_foo < $self->get_foo );
}
};
sub increase_foo {
my ( $self, $amount ) = @_;
$self->set_foo( $self->get_foo + $amount );
}
Class::Agreement is an implementation of behavioral contracts for Perl5. This module allows you to easily add pre- and postconditions to new or existing Perl classes.
This module provides contracts such as dependent contracts, contracts for higher-order functions, and informative messages when things fail.
At the time of this writing, Class::Agreement is one of only two contract implementations that blames contract-breaking components correctly. (See: "Object-oriented Programming Languages Need Well-founded Contracts" at http://citeseer.ist.psu.edu/findler01objectoriented.html.)
Using Class::Agreement lets you specify proper input and output of your functions or methods, thus strengthening your code and allowing you to spot bugs earlier.
<<lessSYNOPSIS
package SomeClass;
use Class::Agreement;
# use base Class::Accessor or Class::MethodMaker,
# or roll your own:
sub new { ... }
invariant {
my ($self) = @_;
$self->count > 0;
};
precondition add_a_positive => sub {
my ( $self, $value ) = @_;
return ( $value >= 0 );
};
sub add_a_positive {
my ( $self, $value ) = @_;
...
}
sub choose_word {
my ( $self, $value ) = @_;
...
}
postcondition choose_word => sub {
return ( result >= 0 );
};
dependent increase_foo => sub {
my ( $self, $amount ) = @_;
my $old_foo = $self->foo;
return sub {
my ( $self, $amount ) = @_;
return ( $old_foo < $self->get_foo );
}
};
sub increase_foo {
my ( $self, $amount ) = @_;
$self->set_foo( $self->get_foo + $amount );
}
Class::Agreement is an implementation of behavioral contracts for Perl5. This module allows you to easily add pre- and postconditions to new or existing Perl classes.
This module provides contracts such as dependent contracts, contracts for higher-order functions, and informative messages when things fail.
At the time of this writing, Class::Agreement is one of only two contract implementations that blames contract-breaking components correctly. (See: "Object-oriented Programming Languages Need Well-founded Contracts" at http://citeseer.ist.psu.edu/findler01objectoriented.html.)
Using Class::Agreement lets you specify proper input and output of your functions or methods, thus strengthening your code and allowing you to spot bugs earlier.
Download (0.027MB)
Added: 2007-02-28 License: Perl Artistic License Price:
968 downloads
Class::InsideOut 1.02
Class::InsideOut is a Perl module with a safe, simple inside-out object construction kit. more>>
Class::InsideOut is a Perl module with a safe, simple inside-out object construction kit.
SYNOPSIS
package My::Class;
use Class::InsideOut qw( public private register id );
public name => my %name; # accessor: name()
private age => my %age; # no accessor
sub new { register( shift ) }
sub greeting {
my $self = shift;
return "Hello, my name is $name{ id $self }";
}
This is a simple, safe and streamlined toolkit for building inside-out objects. Unlike most other inside-out object building modules already on CPAN, this module aims for minimalism and robustness:
- Does not require derived classes to subclass it
- Uses no source filters, attributes or CHECK blocks
- Supports any underlying object type including black-box inheritance
- Does not leak memory on object destruction
- Overloading-safe
- Thread-safe for Perl 5.8 or better
- mod_perl compatible
- Makes no assumption about inheritance or initializer needs
It provides the minimal support necessary for creating safe inside-out objects and generating flexible accessors.
<<lessSYNOPSIS
package My::Class;
use Class::InsideOut qw( public private register id );
public name => my %name; # accessor: name()
private age => my %age; # no accessor
sub new { register( shift ) }
sub greeting {
my $self = shift;
return "Hello, my name is $name{ id $self }";
}
This is a simple, safe and streamlined toolkit for building inside-out objects. Unlike most other inside-out object building modules already on CPAN, this module aims for minimalism and robustness:
- Does not require derived classes to subclass it
- Uses no source filters, attributes or CHECK blocks
- Supports any underlying object type including black-box inheritance
- Does not leak memory on object destruction
- Overloading-safe
- Thread-safe for Perl 5.8 or better
- mod_perl compatible
- Makes no assumption about inheritance or initializer needs
It provides the minimal support necessary for creating safe inside-out objects and generating flexible accessors.
Download (0.047MB)
Added: 2006-09-27 License: Perl Artistic License Price:
1122 downloads
Class::Interfaces 0.04
Class::Interfaces is a Per module for defining interface classes inline. more>>
Class::Interfaces is a Per module for defining interface classes inline.
SYNOPSIS
# define some simple interfaces
use Class::Interfaces (
Serializable => [ pack, unpack ],
Printable => [ toString ],
Iterable => [ iterator ],
Iterator => [ hasNext, next ]
);
# or some more complex ones ...
# interface can also inherit from
# other interfaces using this form
use Class::Interfaces (
BiDirectionalIterator => {
isa => Iterator,
methods => [ hasPrev, prev ]
},
ResetableIterator => {
isa => Iterator,
methods => [ reset ]
},
# we even support multiple inheritance
ResetableBiDirectionalIterator => {
isa => [ ResetableIterator, BiDirectionalIterator ]
}
);
# it is also possible to create an
# empty interface, sometimes called
# a marker interface
use Class::Interfaces (
JustAMarker => undef
);
This module provides a simple means to define abstract class interfaces, which can be used to program using the concepts of interface polymorphism.
<<lessSYNOPSIS
# define some simple interfaces
use Class::Interfaces (
Serializable => [ pack, unpack ],
Printable => [ toString ],
Iterable => [ iterator ],
Iterator => [ hasNext, next ]
);
# or some more complex ones ...
# interface can also inherit from
# other interfaces using this form
use Class::Interfaces (
BiDirectionalIterator => {
isa => Iterator,
methods => [ hasPrev, prev ]
},
ResetableIterator => {
isa => Iterator,
methods => [ reset ]
},
# we even support multiple inheritance
ResetableBiDirectionalIterator => {
isa => [ ResetableIterator, BiDirectionalIterator ]
}
);
# it is also possible to create an
# empty interface, sometimes called
# a marker interface
use Class::Interfaces (
JustAMarker => undef
);
This module provides a simple means to define abstract class interfaces, which can be used to program using the concepts of interface polymorphism.
Download (0.006MB)
Added: 2006-10-05 License: Perl Artistic License Price:
1115 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 classes v2 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