class file has wrong version
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 3006
Class::StrongSingleton 0.02
Class::StrongSingleton is a stronger and more secure Singleton base class. more>>
Class::StrongSingleton is a stronger and more secure Singleton base class.
SYNOPSIS
package My::Singleton::Class;
use base qw(Class::StrongSingleton);
sub new {
my ($class, %my_params) = @_;
# create our object instance
my $instance = { %my_params };
bless($instance, $class);
# and initialize it as a singleton
$instance->_init_StrongSingleton();
return $instance;
}
1;
# later in your code ...
# create the first instance of our class
my $instance = My::Singleton::Class->new(param => "value");
# try to create a new one again, and
# you end up with the same instance, not
# a new one
my $instance2 = My::Singleton::Class->new(param => "other value");
# calling instance returns the singleton
# instance expected
my $instance3 = My::Singleton::Class->instance();
# although rarely needed, if you have to
# you can destroy the singleton
# either through the instance
$instance->DESTROY();
# or through the class
My::Singleton::Class->DESTROY();
# of course, this is assuming you
# did not override DESTORY yourself
# Also calling instance before calling new
# will returns a new singleton instance
my $instance = My::Singleton::Class->instance();
This module is an alternative to Class::Singleton and Class::WeakSingleton, and provides a more secure Singleton class in that it takes steps to prevent the possibility of accidental creation of multiple instances and/or the overwriting of existsing Singleton instances. For a detailed comparison please see the "SEE ALSO" section.
Here is a description of how it all works. First, the user creates the first Singleton instance of the class in the normal way.
my $obj = My::Singleton::Class->new("variable", "parameter");
This instance is then stored inside a lexically scoped variable within the Class::StrongSingleton package. This prevents the variable from being accessed by anything but methods from the Class::StrongSingleton package. At this point as well, the new method to the class is overridden so that it will always return the Singleton instance. This prevents any accidental overwriting of the Singleton instance. This means that any of the follow lines of code all produce the same instance:
my $instance = $obj->instance();
my $instance = My::Singleton::Class->instance();
my $instance = $obj->new();
my $instance = My::Singleton::Class->new();
Personally, I see this an an improvement over the usual Gang of Four style Singletons which discourages the use of the new method entirely. Through this method, a user can be able to use the Singleton class in a normal way, not having to know its actually a Singleton. This can be handy if your design changes and you no longer need the class as a Singleton.
<<lessSYNOPSIS
package My::Singleton::Class;
use base qw(Class::StrongSingleton);
sub new {
my ($class, %my_params) = @_;
# create our object instance
my $instance = { %my_params };
bless($instance, $class);
# and initialize it as a singleton
$instance->_init_StrongSingleton();
return $instance;
}
1;
# later in your code ...
# create the first instance of our class
my $instance = My::Singleton::Class->new(param => "value");
# try to create a new one again, and
# you end up with the same instance, not
# a new one
my $instance2 = My::Singleton::Class->new(param => "other value");
# calling instance returns the singleton
# instance expected
my $instance3 = My::Singleton::Class->instance();
# although rarely needed, if you have to
# you can destroy the singleton
# either through the instance
$instance->DESTROY();
# or through the class
My::Singleton::Class->DESTROY();
# of course, this is assuming you
# did not override DESTORY yourself
# Also calling instance before calling new
# will returns a new singleton instance
my $instance = My::Singleton::Class->instance();
This module is an alternative to Class::Singleton and Class::WeakSingleton, and provides a more secure Singleton class in that it takes steps to prevent the possibility of accidental creation of multiple instances and/or the overwriting of existsing Singleton instances. For a detailed comparison please see the "SEE ALSO" section.
Here is a description of how it all works. First, the user creates the first Singleton instance of the class in the normal way.
my $obj = My::Singleton::Class->new("variable", "parameter");
This instance is then stored inside a lexically scoped variable within the Class::StrongSingleton package. This prevents the variable from being accessed by anything but methods from the Class::StrongSingleton package. At this point as well, the new method to the class is overridden so that it will always return the Singleton instance. This prevents any accidental overwriting of the Singleton instance. This means that any of the follow lines of code all produce the same instance:
my $instance = $obj->instance();
my $instance = My::Singleton::Class->instance();
my $instance = $obj->new();
my $instance = My::Singleton::Class->new();
Personally, I see this an an improvement over the usual Gang of Four style Singletons which discourages the use of the new method entirely. Through this method, a user can be able to use the Singleton class in a normal way, not having to know its actually a Singleton. This can be handy if your design changes and you no longer need the class as a Singleton.
Download (0.006MB)
Added: 2007-06-19 License: Perl Artistic License Price:
858 downloads
Class::Delegation 1.7.1
Class::Delegation is a Perl object-oriented delegation. more>>
Class::Delegation is a Perl object-oriented delegation.
SYNOPSIS
package Car;
use Class::Delegation
send => steer,
to => ["left_front_wheel", "right_front_wheel"],
send => drive,
to => ["right_rear_wheel", "left_rear_wheel"],
as => ["rotate_clockwise", "rotate_anticlockwise"]
send => power,
to => flywheel,
as => brake,
send => brake,
to => qr/.*_wheel$/,
send => halt
to => -SELF,
as => brake,
send => qr/^MP_(.+)/,
to => mp3,
as => sub { $1 },
send => -OTHER,
to => mp3,
send => debug,
to => -ALL,
as => dump,
send => -ALL,
to => logger,
;
<<lessSYNOPSIS
package Car;
use Class::Delegation
send => steer,
to => ["left_front_wheel", "right_front_wheel"],
send => drive,
to => ["right_rear_wheel", "left_rear_wheel"],
as => ["rotate_clockwise", "rotate_anticlockwise"]
send => power,
to => flywheel,
as => brake,
send => brake,
to => qr/.*_wheel$/,
send => halt
to => -SELF,
as => brake,
send => qr/^MP_(.+)/,
to => mp3,
as => sub { $1 },
send => -OTHER,
to => mp3,
send => debug,
to => -ALL,
as => dump,
send => -ALL,
to => logger,
;
Download (0.014MB)
Added: 2006-11-11 License: Perl Artistic License Price:
1077 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.Logger.php3 1.0
class.Logger.php3 is used to maintain persistant log files in PHP3 applications as efficiently as possible. more>>
class.Logger.php3 is used to maintain persistant log files in PHP3 applications as efficiently as possible.
Using Logger, your programs can append log entries to as many different files as you need, using only 1 fopen() call and 1 fclose() call per log file.
Loggers primary use is for debugging personal programs when you cant or dont want to log via error_log().
SYNOPSIS
include("class.Logger.php3");
$logger = new Logger("/path/to/log/file/root_directory");
$logger->initialize(
array(
ERRLOG => error_log,
DEBUGLOG => debug_log
)
);
$logger->log(ERRLOG,"This is an error_log entry");
$logger->log(DEBUGLOG,"This is logged to the debug_log");
$logger->close_logs();
exit;
<<lessUsing Logger, your programs can append log entries to as many different files as you need, using only 1 fopen() call and 1 fclose() call per log file.
Loggers primary use is for debugging personal programs when you cant or dont want to log via error_log().
SYNOPSIS
include("class.Logger.php3");
$logger = new Logger("/path/to/log/file/root_directory");
$logger->initialize(
array(
ERRLOG => error_log,
DEBUGLOG => debug_log
)
);
$logger->log(ERRLOG,"This is an error_log entry");
$logger->log(DEBUGLOG,"This is logged to the debug_log");
$logger->close_logs();
exit;
Download (0.008MB)
Added: 2006-11-01 License: GPL (GNU General Public License) Price:
1088 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
Class::Phrasebook 0.88
Class::Phrasebook is a Perl module that implements the Phrasebook pattern. more>>
Class::Phrasebook is a Perl module that implements the Phrasebook pattern.
SYNOPSIS
use Class::Phrasebook;
my $pb = new Class::Phrasebook($log, "test.xml");
$pb->load("NL"); # using Dutch as the language
$phrase = $pb->get("ADDRESS",
{ street => "Chaim Levanon",
number => 88,
city => "Tel Aviv" } );
This class implements the Phrasebook pattern. It lets us create dictionaries of phrases. Each phrase can be accessed by a unique key. Each phrase may have placeholders. Group of phrases are kept in a dictionary. The first dictionary is the default one - which means that it will always be read. One of the dictionaries might be used to override the default one. The phrases are kept in an XML document.
<<lessSYNOPSIS
use Class::Phrasebook;
my $pb = new Class::Phrasebook($log, "test.xml");
$pb->load("NL"); # using Dutch as the language
$phrase = $pb->get("ADDRESS",
{ street => "Chaim Levanon",
number => 88,
city => "Tel Aviv" } );
This class implements the Phrasebook pattern. It lets us create dictionaries of phrases. Each phrase can be accessed by a unique key. Each phrase may have placeholders. Group of phrases are kept in a dictionary. The first dictionary is the default one - which means that it will always be read. One of the dictionaries might be used to override the default one. The phrases are kept in an XML document.
Download (0.018MB)
Added: 2006-09-19 License: Perl Artistic License Price:
1131 downloads
Class::AbstractLogic 0.01_01
Class::AbstractLogic is a Perl module to handle Logic Abstractions. more>>
Class::AbstractLogic is a Perl module to handle Logic Abstractions.
SYNOPSIS
# the logic class definition
package My::Logic::Foo;
use Class::AbstractLogic-base;
# a logic action
action add,
needs [qw(a b)],
verify { a => sub { /^d+$/ }, b => sub { /^d+$/ } },
sub { $_{a} + $_{b} };
1;
...
# logic module manager creation
use Class::AbstractLogic;
my $calm = Class::AbstractLogic::Manager->new;
# loading a logic class
$calm->load_logic(Foo => My::Logic::Foo);
# requesting a result from a logic method
my $result = $calm->logic(Foo)->add(a => 11, b => 12);
# $result will be false if an exception was caught
if ($result) {
print result was . $result->value . "n";
}
else {
print exception raised: . $result->key . "n";
print error message: . $result->error . "n";
}
<<lessSYNOPSIS
# the logic class definition
package My::Logic::Foo;
use Class::AbstractLogic-base;
# a logic action
action add,
needs [qw(a b)],
verify { a => sub { /^d+$/ }, b => sub { /^d+$/ } },
sub { $_{a} + $_{b} };
1;
...
# logic module manager creation
use Class::AbstractLogic;
my $calm = Class::AbstractLogic::Manager->new;
# loading a logic class
$calm->load_logic(Foo => My::Logic::Foo);
# requesting a result from a logic method
my $result = $calm->logic(Foo)->add(a => 11, b => 12);
# $result will be false if an exception was caught
if ($result) {
print result was . $result->value . "n";
}
else {
print exception raised: . $result->key . "n";
print error message: . $result->error . "n";
}
Download (0.016MB)
Added: 2007-08-01 License: Perl Artistic License Price:
814 downloads
Class::Method::hash 2.08
Class::Method::hash is a Perl module that helps you create methods for handling a hash value. more>>
Class::Method::hash is a Perl module that helps you create methods for handling a hash value.
SYNOPSIS
use Class::MethodMaker
[ hash => [qw/ x /] ];
$instance->x; # empty
$instance->x(a => 1, b => 2, c => 3);
$instance->x_count == 3; # true
$instance->x = (b => 5, d => 8); # Note this *replaces* the hash,
# not adds to it
$instance->x_index(b) == 5; # true
$instance->x_exists(c); # false
$instance->x_exists(d); # true
Creates methods to handle hash values in an object. For a component named x, by default creates methods x, x_reset, x_clear, x_isset, x_count, x_index, x_keys, x_values, x_each, x_exists, x_delete, x_set, x_get.
<<lessSYNOPSIS
use Class::MethodMaker
[ hash => [qw/ x /] ];
$instance->x; # empty
$instance->x(a => 1, b => 2, c => 3);
$instance->x_count == 3; # true
$instance->x = (b => 5, d => 8); # Note this *replaces* the hash,
# not adds to it
$instance->x_index(b) == 5; # true
$instance->x_exists(c); # false
$instance->x_exists(d); # true
Creates methods to handle hash values in an object. For a component named x, by default creates methods x, x_reset, x_clear, x_isset, x_count, x_index, x_keys, x_values, x_each, x_exists, x_delete, x_set, x_get.
Download (0.087MB)
Added: 2007-07-05 License: Perl Artistic License Price:
841 downloads
Class::Tangram 1.57
Class::Tangram is a Perl module for tangram-friendly classes, DWIM attributes. more>>
Class::Tangram is a Perl module for tangram-friendly classes, DWIM attributes.
SYNOPSIS
package MyObject;
use base qw(Class::Tangram);
our $fields = { int => [ qw(foo bar) ],
string => [ qw(baz quux) ] };
package main;
my $object = MyObject->new(foo => 2, baz => "hello");
print $object->baz(); # prints "hello"
$object->set_quux("Something");
$object->set_foo("Something"); # dies - not an integer
Class::Tangram is a tool for defining objects attributes. Simply define your objects fields/attributes using the same data structure introduced in _A Guided Tour of Tangram_ (see "SEE ALSO") and detailed in Tangram::Schema, and you get objects that work As Youd Expect(tm).
Class::Tangram has no dependancy upon Tangram, and vice versa. Neither requires anything special of your objects, nor do they insert any special fields into your objects. This is a very important feature with innumerable benefits, and few (if any) other object persistence tools have this feature.
So, fluff aside, lets run through how you use Class::Tangram to make objects.
First, you decide upon the attributes your object is going to have. You might do this using UML, or you might pick an existing database table and declare each column to be an attribute (you can leave out "id"; that one is implicit; also, leave out foreign keys until later).
<<lessSYNOPSIS
package MyObject;
use base qw(Class::Tangram);
our $fields = { int => [ qw(foo bar) ],
string => [ qw(baz quux) ] };
package main;
my $object = MyObject->new(foo => 2, baz => "hello");
print $object->baz(); # prints "hello"
$object->set_quux("Something");
$object->set_foo("Something"); # dies - not an integer
Class::Tangram is a tool for defining objects attributes. Simply define your objects fields/attributes using the same data structure introduced in _A Guided Tour of Tangram_ (see "SEE ALSO") and detailed in Tangram::Schema, and you get objects that work As Youd Expect(tm).
Class::Tangram has no dependancy upon Tangram, and vice versa. Neither requires anything special of your objects, nor do they insert any special fields into your objects. This is a very important feature with innumerable benefits, and few (if any) other object persistence tools have this feature.
So, fluff aside, lets run through how you use Class::Tangram to make objects.
First, you decide upon the attributes your object is going to have. You might do this using UML, or you might pick an existing database table and declare each column to be an attribute (you can leave out "id"; that one is implicit; also, leave out foreign keys until later).
Download (0.049MB)
Added: 2006-10-05 License: Perl Artistic License Price:
1114 downloads
Class::Driver 0.005
Class::Driver is a Perl module to generate driver (composite) class hierarchies on-the-fly. more>>
EXAMPLE
# This is a really long synopsis, but hopefully it will give you an idea...
package MyPackage;
use Class::Driver;
use base q(Class::Driver);
our %drivers;
return 1;
sub new {
my($class, %args) = @_;
die "mime_type is required" unless($args{mime_type});
die "no driver to handle type $args{mime_type}"
unless($drivers{$args{mime_type}});
return $class->driver_load($drivers{$args{mime_type}}, %args);
}
sub driver_new {
my($class, %args) = @_;
return bless %args, $class;
}
sub driver_required { 1; }
sub driver_requied_here { 0; }
package MyPackage::avi;
use MyPackage;
use base q(MyPackage);
use Video::Info;
$MyPackage::drivers{video/x-msvideo} = avi;
return 1;
sub driver { "avi"; }
sub driver_new {
my($class, %args) = @_;
die "file is a required parameter for $args{mime_type} files"
unless($args{file});
$args{info} = Video::Info->new(-file => $args{file})
or die "Failed to create a Video::Info object for $args{file}";
return $class->SUPER::driver_new(%args);
}
sub duration {
my $self = shift;
return $args{info}->duration;
}
package MyPackage::mp3;
use base q(MyPackage);
use MP3::Info;
$MyPackage::drivers{audio/mpeg} = mp3;
## (etc...)
package main;
my $foo = MyPackage->new(file => foobar.mp3, mime_type => audio/mpeg);
print "foobar.mp3 is ", $foo->duration, " seconds long.n";
Download (0.011MB)
Added: 2006-11-14 License: Perl Artistic License Price:
1075 downloads
Class::Struct::FIELDS 1.1
Class::Struct::FIELDS module combine Class::Struct, base and fields. more>>
Class::Struct::FIELDS module combine Class::Struct, base and fields.
SYNOPSIS
(This page documents Class::Struct::FIELDS v.1.1.)
use Class::Struct::FIELDS;
# declare struct, based on fields, explicit class name:
struct (CLASS_NAME => { ELEMENT_NAME => ELEMENT_TYPE, ... });
use Class::Struct::FIELDS;
# declare struct, based on fields, explicit class name
# with inheritance:
struct (CLASS_NAME => [qw(BASE_CLASSES ...)],
{ ELEMENT_NAME => ELEMENT_TYPE, ... });
package CLASS_NAME;
use Class::Struct::FIELDS;
# declare struct, based on fields, implicit class name:
struct (ELEMENT_NAME => ELEMENT_TYPE, ...);
package CLASS_NAME;
use Class::Struct::FIELDS;
# declare struct, based on fields, implicit class name
# with inheritance:
struct ([qw(BASE_CLASSES ...)], ELEMENT_NAME => ELEMENT_TYPE, ...);
package MyObj;
use Class::Struct::FIELDS;
# declare struct with four types of elements:
struct (s => $, a => @, h => %, x => &, c => My_Other_Class);
$obj = new MyObj; # constructor
# scalar type accessor:
$element_value = $obj->s; # element value
$obj->s (new value); # assign to element
# array type accessor:
$ary_ref = $obj->a; # reference to whole array
$ary_element_value = $obj->a->[2]; # array element value
$ary_element_value = $obj->a (2); # same thing
$obj->a->[2] = new value; # assign to array element
$obj->a (2, newer value); # same thing
# hash type accessor:
$hash_ref = $obj->h; # reference to whole hash
$hash_element_value = $obj->h->{x}; # hash element value
$hash_element_value = $obj->h (x); # same thing
$obj->h->{x} = new value; # assign to hash element
$obj->h (x, newer value); # same thing
# code type accessor:
$code_ref = $obj->x; # reference to code
$obj->x->(...); # call code
$obj->x (sub {...}); # assign to element
# regexp type accessor:
$regexp = $obj->r; # reference to code
$string =~ m/$obj->r/; # match regexp
$obj->r (qr/ ... /); # assign to element
# class type accessor:
$element_value = $obj->c; # object reference
$obj->c->method (...); # call method of object
$obj->c (My_Other_Class::->new); # assign a new object
Class::Struct::FIELDS exports a single function, struct. Given a list of element names and types, and optionally a class name and/or an array reference of base classes, struct creates a Perl 5 class that implements a "struct-like" data structure with inheritance.
The new class is given a constructor method, new, for creating struct objects.
Each element in the struct data has an accessor method, which is used to assign to the element and to fetch its value. The default accessor can be overridden by declaring a sub of the same name in the package. (See Example 2.)
Each elements type can be scalar, array, hash, code or class.
<<lessSYNOPSIS
(This page documents Class::Struct::FIELDS v.1.1.)
use Class::Struct::FIELDS;
# declare struct, based on fields, explicit class name:
struct (CLASS_NAME => { ELEMENT_NAME => ELEMENT_TYPE, ... });
use Class::Struct::FIELDS;
# declare struct, based on fields, explicit class name
# with inheritance:
struct (CLASS_NAME => [qw(BASE_CLASSES ...)],
{ ELEMENT_NAME => ELEMENT_TYPE, ... });
package CLASS_NAME;
use Class::Struct::FIELDS;
# declare struct, based on fields, implicit class name:
struct (ELEMENT_NAME => ELEMENT_TYPE, ...);
package CLASS_NAME;
use Class::Struct::FIELDS;
# declare struct, based on fields, implicit class name
# with inheritance:
struct ([qw(BASE_CLASSES ...)], ELEMENT_NAME => ELEMENT_TYPE, ...);
package MyObj;
use Class::Struct::FIELDS;
# declare struct with four types of elements:
struct (s => $, a => @, h => %, x => &, c => My_Other_Class);
$obj = new MyObj; # constructor
# scalar type accessor:
$element_value = $obj->s; # element value
$obj->s (new value); # assign to element
# array type accessor:
$ary_ref = $obj->a; # reference to whole array
$ary_element_value = $obj->a->[2]; # array element value
$ary_element_value = $obj->a (2); # same thing
$obj->a->[2] = new value; # assign to array element
$obj->a (2, newer value); # same thing
# hash type accessor:
$hash_ref = $obj->h; # reference to whole hash
$hash_element_value = $obj->h->{x}; # hash element value
$hash_element_value = $obj->h (x); # same thing
$obj->h->{x} = new value; # assign to hash element
$obj->h (x, newer value); # same thing
# code type accessor:
$code_ref = $obj->x; # reference to code
$obj->x->(...); # call code
$obj->x (sub {...}); # assign to element
# regexp type accessor:
$regexp = $obj->r; # reference to code
$string =~ m/$obj->r/; # match regexp
$obj->r (qr/ ... /); # assign to element
# class type accessor:
$element_value = $obj->c; # object reference
$obj->c->method (...); # call method of object
$obj->c (My_Other_Class::->new); # assign a new object
Class::Struct::FIELDS exports a single function, struct. Given a list of element names and types, and optionally a class name and/or an array reference of base classes, struct creates a Perl 5 class that implements a "struct-like" data structure with inheritance.
The new class is given a constructor method, new, for creating struct objects.
Each element in the struct data has an accessor method, which is used to assign to the element and to fetch its value. The default accessor can be overridden by declaring a sub of the same name in the package. (See Example 2.)
Each elements type can be scalar, array, hash, code or class.
Download (0.018MB)
Added: 2007-07-11 License: Perl Artistic License Price:
835 downloads
Class::Classgen::New 3.03
Class::Classgen::New is a Perl module that creates the new() method for classes generated by classgen. more>>
Class::Classgen::New is a Perl module that creates the new() method for classes generated by classgen.
SYNOPSIS
Used within classgen.
The main purpose of New.pm is to write the new() method for a class generated by classgen. It provides code to derive local instance variables with my for all specified instance variables. It provides code to store them within an anonymous hash (only way in the current version). Finally, this hash is blessed into the desired class.
Methods generated by New.pm
In the blessing section of the generated new() method:
inherit_from(): copies the entries of the blessed {} from the base class into the blessed {} of the derived class.
ENVIRONMENT
Nothing special. Just use Perl5.
DIAGNOSTICS
There is no special diagnostics. New.pm is used within classgen which is called with the -w option.
<<lessSYNOPSIS
Used within classgen.
The main purpose of New.pm is to write the new() method for a class generated by classgen. It provides code to derive local instance variables with my for all specified instance variables. It provides code to store them within an anonymous hash (only way in the current version). Finally, this hash is blessed into the desired class.
Methods generated by New.pm
In the blessing section of the generated new() method:
inherit_from(): copies the entries of the blessed {} from the base class into the blessed {} of the derived class.
ENVIRONMENT
Nothing special. Just use Perl5.
DIAGNOSTICS
There is no special diagnostics. New.pm is used within classgen which is called with the -w option.
Download (0.024MB)
Added: 2007-07-10 License: Perl Artistic License Price:
839 downloads
Class::Accessor::Fast::Contained 0.05
Class::Accessor::Fast::Contained is a Perl module for fast accessors with data containment. more>>
Class::Accessor::Fast::Contained is a Perl module for fast accessors with data containment.
SYNOPSIS
package Foo;
use base qw(Class::Accessor::Fast::Contained);
# The rest is the same as Class::Accessor::Fast
This module does two things differently to the venerable Class::Accessor::Fast :
Fields are stored at arms-length within a single hash value of $self, rather than directly in the $self blessed referent.
new() allows mixin into an existing object, rather than creating and returning a new blessed hashref. To do this, just call something like:
my $self = Some::Other::Class->new;
$self = $self->Class::Accessor::Fast::Contained::new;
Note that the mixin code only supports objects which use a blessed hash reference or a blessed typeglob reference.
An alias setup() is available which does the same as new() but might make more sense if being used in this way.
<<lessSYNOPSIS
package Foo;
use base qw(Class::Accessor::Fast::Contained);
# The rest is the same as Class::Accessor::Fast
This module does two things differently to the venerable Class::Accessor::Fast :
Fields are stored at arms-length within a single hash value of $self, rather than directly in the $self blessed referent.
new() allows mixin into an existing object, rather than creating and returning a new blessed hashref. To do this, just call something like:
my $self = Some::Other::Class->new;
$self = $self->Class::Accessor::Fast::Contained::new;
Note that the mixin code only supports objects which use a blessed hash reference or a blessed typeglob reference.
An alias setup() is available which does the same as new() but might make more sense if being used in this way.
Download (0.005MB)
Added: 2007-03-15 License: GPL (GNU General Public License) Price:
953 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
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 file has wrong version 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