Main > Free Download Search >

Free classes software for linux

classes

Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 2591
Class::AbstractLogic 0.01_01

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";
}

<<less
Download (0.016MB)
Added: 2007-08-01 License: Perl Artistic License Price:
814 downloads
Class::Generate 1.09

Class::Generate 1.09


Class::Generate is a Perl module that can generate Perl class hierarchies. more>>
Class::Generate is a Perl module that can generate Perl class hierarchies.

SYNOPSIS

use Class::Generate qw(class subclass delete_class);

# Declare class Class_Name, with the following types of members:
class
Class_Name => [
s => $, # scalar
a => @, # array
h => %, # hash
c => Class, # Class
c_a => @Class, # array of Class
c_h => %Class, # hash of Class
&m => body, # method
];

# Allocate an instance of class_name, with members initialized to the
# given values (pass arrays and hashes using references).
$obj = Class_Name->new ( s => scalar,
a => [ values ],
h => { key1 => v1, ... },
c => Class->new,
c_a => [ Class->new, ... ],
c_h => [ key1 => Class->new, ... ] );

# Scalar type accessor:
$obj->s($value); # Assign $value to member s.
$member_value = $obj->s; # Access members value.

# (Class) Array type accessor:
$obj->a([value1, value2, ...]); # Assign whole array to member.
$obj->a(2, $value); # Assign $value to array member 2.
$obj->add_a($value); # Append $value to end of array.
@a = $obj->a; # Access whole array.
$ary_member_value = $obj->a(2); # Access array member 2.
$s = $obj->a_size; # Return size of array.
$value = $obj->last_a; # Return last element of array.

# (Class) Hash type accessor:
$obj->h({ k_1=>v1, ..., k_n=>v_n }) # Assign whole hash to member.
$obj->h($key, $value); # Assign $value to hash member $key.
%hash = $obj->h; # Access whole hash.
$hash_member_value = $obj->h($key); # Access hash member value $key.
$obj->delete_h($key); # Delete slot occupied by $key.
@keys = $obj->h_keys; # Access keys of member h.
@values = $obj->h_values; # Access values of member h.

$another = $obj->copy; # Copy an object.
if ( $obj->equals($another) ) { ... } # Test equality.

subclass s => [ ], -parent => class_name;

The Class::Generate package exports functions that take as arguments a class specification and create from these specifications a Perl 5 class. The specification language allows many object-oriented constructs: typed members, inheritance, private members, required members, default values, object methods, class methods, class variables, and more.

CPAN contains similar packages. Why another? Because object-oriented programming, especially in a dynamic language like Perl, is a complicated endeavor. I wanted a package that would work very hard to catch the errors you (well, I anyway) commonly make. I wanted a package that could help me enforce the contract of object-oriented programming. I also wanted it to get out of my way when I asked.

<<less
Download (0.052MB)
Added: 2007-07-31 License: Perl Artistic License Price:
815 downloads
Class::Prototyped::Mixin 2.4

Class::Prototyped::Mixin 2.4


Class::Prototyped::Mixin Perl module contains Mixin Support for Class::Prototyped. more>>
Class::Prototyped::Mixin Perl module contains Mixin Support for Class::Prototyped.

SYNOPSIS

Usage one: whip up a class and toss it in a scalar
package HelloWorld;

sub hello {
my ($self, $age) = @_;
return "Hello World! I am $age years old"
}


package HelloWorld::Uppercase;
use base qw(Class::Prototyped);

__PACKAGE__->reflect->addSlot(
[qw(hello superable)] => sub {
my $self = shift;
my $ret = $self->reflect->super(hello, @_);
uc $ret
}
);


package HelloWorld::Bold;
use base qw(Class::Prototyped);

__PACKAGE__->reflect->addSlot(
[qw(hello superable)] => sub {
my $self = shift;
my $ret = $self->reflect->super(hello, @_);
"< b >$ret< /b >";
}
);


package HelloWorld::Italic;
use base qw(Class::Prototyped);

__PACKAGE__->reflect->addSlot(
[qw(hello superable)] => sub {
my $self = shift;
my $ret = $self->reflect->super(hello, @_);
"< i >$ret< /i >";
}
);

# script.pl - now the whipping begins
use Class::Prototyped::Mixin qw(mixin);
my $runtime = mixin(
HelloWorld => HelloWorld::Uppercase, HelloWorld::Italic
);

print $runtime->hello(74);
< i >HELLO WORLD! I AM 74 YEARS OLD< /i >
Usage two: create hierarchy and install in a Class::Prototyped package
package CompileTime;
use Class::Prototyped::Mixin qw(mixin);

my $uclass = mixin(
HelloWorld => HelloWorld::Uppercase, HelloWorld::Bold
);

__PACKAGE__->reflect->addSlot(
* => $uclass
);


# script.pl
use CompileTime;

print CompileTime->hello(88);
< b >HELLO WORLD! I AM 88 YEARS OLD< /b >

<<less
Download (0.011MB)
Added: 2007-07-31 License: Perl Artistic License Price:
815 downloads
Class::Bits 0.05

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

<<less
Download (0.004MB)
Added: 2007-07-30 License: Perl Artistic License Price:
816 downloads
Class::DispatchToAll 0.11

Class::DispatchToAll 0.11


Class::DispatchToAll Perl module can dispatch a method call to all inherited methods. more>>
Class::DispatchToAll Perl module can dispatch a method call to all inherited methods.

SYNOPSIS

package My::Class;
our @ISA=qw(SomeClass SomeOtherClass More::Classes);
use Class::DispatchToAll qw(dispatch_to_all);

my $self=bless {},My::Class # not a proper constructor, I know..

# this calls some_method in all Classes My::Class inherits from
# and all classes those classes inherit from, and all ... you get
# the point.
$self->dispatch_to_all(some_method);

# saves all return values from all calls in an array
my @returns=$self->dispatch_to_all(some_method);

See the Docs of Damian Conways Module Class::Delegation for a good introduction about Dispatching vs. Inheritance.

Class::DispatchToAll enables you to call all instantances of a method in your inheritance tree (or labyrinth..).

The standard Perl behaviour is to call only the lefternmost instance it can fing doing a depth first traversial.

Imagine the following class structure:
C
/
A B C::C
/ /
A::A D
/
My::Class

Perl will try to find a method in this mess in this order:

My::Class -> A::A -> A -> B -> D -> B -> C::C -> C
(Note that it will look twice in B because B is a parent of both A::A and D))

As soon as Perl finds the method somewhere, it will short-circuit out of its search and invoke the method.

And that is exactly the behaviour Class::DispatchToAll changes.

If you use dispatch_to_all (provided by Class::DispatchToAll) to call your method, Perl will look in all of the aforementioned packages and run all the methods it can find. It will even collect all the return values and return them to you as an array, if you want it too.

<<less
Download (0.005MB)
Added: 2007-07-21 License: Perl Artistic License Price:
825 downloads
Class::Classless 1.35

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".)

<<less
Download (0.023MB)
Added: 2007-07-19 License: Perl Artistic License Price:
827 downloads
Class::IntrospectionMethods::Catalog 1.003

Class::IntrospectionMethods::Catalog 1.003


Class::IntrospectionMethods::Catalog can manage catalogs from IntrospectionMethods. more>>
Class::IntrospectionMethods::Catalog can manage catalogs from IntrospectionMethods.

Exported functions

set_method_info( target_class, method_name, info_ref )

Store construction info for method method_name of class target_class.

set_global_catalog (target_class, ...)

Store catalog informations. The first parameter is the class featuring the methods declared in the global catalog.

Following paramaters is a set of named paramaters (e.g. key => value):

name

Mandatory name for the global catalog

list

array ref containing the list of slot and catalog. E.g.:

list => [
[qw/foo bar baz/] => foo_catalog,
[qw/a b z/] => alpha_catalog,
my_object => my_catalog
],
isa

Optional hash ref declaring a containment for catalog. E.g:

list => [ foo => USER ,
admin => ROOT ],
isa => { USER => ROOT }

Then the ROOT catalog will return foo, and the USER catalog will return foo and admin.

help

Optional hash ref (slot_name => help). Store some help information for each slot.

set_global_catalog will construct:

A ClassCatalog object containing the global catalog informations.

A sub_ref containing the ClassCatalog object in a closure.

Returns ( slot_name, sub_ref ). The sub_ref is to be installed in the target class.

When called as a class method, the subref will return the ClassCatalog object. When called as a target class method, the subref will return an ObjectCatalog object associated to the ClassCatalog object stored in the closure.

These 2 object have the same API. ObjectCatalog is used to contain catalog changes that may occur at run-time. ClassCatalog informations will not change.

<<less
Download (0.031MB)
Added: 2007-07-18 License: Perl Artistic License Price:
829 downloads
Class::Struct::FIELDS 1.1

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.

<<less
Download (0.018MB)
Added: 2007-07-11 License: Perl Artistic License Price:
835 downloads
Class::Classgen::New 3.03

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.

<<less
Download (0.024MB)
Added: 2007-07-10 License: Perl Artistic License Price:
839 downloads
Class::Multimethods::Pure 0.13

Class::Multimethods::Pure 0.13


Class::Multimethods::Pure is a Perl module that contains a method-ordered multimethod dispatch. more>>
Class::Multimethods::Pure is a Perl module that contains a method-ordered multimethod dispatch.

SYNOPSIS

use Class::Multimethods::Pure;

package A;
sub magic { rand() > 0.5 }
package B;
use base A;
package C;
use base A;

BEGIN {
multi foo => (A, A) => sub {
"Generic catch-all";
};

multi foo => (A, B) => sub {
"More specific";
};

multi foo => (subtype(A, sub { $_[0]->magic }), A) => sub {
"This gets called half the time instead of catch-all";
};

multi foo => (any(B, C), A) => sub {
"Accepts B or C as the first argument, but not A"
};
}

<<less
Download (0.015MB)
Added: 2007-07-05 License: Perl Artistic License Price:
843 downloads
Nameko 20070620 (Low Level Classes)

Nameko 20070620 (Low Level Classes)


Nameko was born as a simple PHP webmail. more>>
Nameko was born as a simple PHP webmail. Now Nameko is much more than this: its a set of classes to manage e-mail with PHP.
The project can retrieve message from a POP3 server, parse e-mails, send email through SMTP server, and so on.
The mail parser was totally rewritten from the original version: now its greatly improved, and it can read every kind of email.
The Nameko webmail has also been totally rewritten: now it has a great interface, fast, powerful, with a lot of advanced tools.
Each component of the webmail is customizable, with a sort of plug-ins system: you can add only the plug-ins for the functions you really need.
The basic version on Nameko is always a one-file script: so simple tu set up!
Enhancements:
- This release include great performance improvements, making parsing also of heavy email (> 50MB) much faster.
- It includes some code cleanup and small bugfixes.
<<less
Download (0.020MB)
Added: 2007-06-22 License: GPL (GNU General Public License) Price:
859 downloads
Class::Declare 0.08

Class::Declare 0.08


Class::Declare is a Perl module created to declare classes with public, private and protected attributes and methods. more>>
Class::Declare is a Perl module created to declare classes with public, private and protected attributes and methods.

SYNOPSIS

package My::Class;

use strict;
use warnings;
use base qw( Class::Declare );

__PACKAGE__->declare(

public => { public_attr => 42 } ,
private => { private_attr => Foo } ,
protected => { protected_attr => Bar } ,
class => { class_attr => [ 3.141 ] }
static => { static_attr => { a => 1 } } ,
restricted => { restricted_attr => string } ,
abstract => abstract_attr ,
friends => main::trustedsub ,
new => [ public_attr , private_attr ] ,
init => sub { # object initialisation
...
1;
} ,
strict => 0

);

sub publicmethod {
my $self = __PACKAGE__->public( shift );
...
}

sub privatemethod {
my $self = __PACKAGE__->private( shift );
...
}

sub protectedmethod {
my $self = __PACKAGE__->protected( shift );
...
}

sub classmethod {
my $self = __PACKAGE__->class( shift );
...
}

sub staticmethod {
my $self = __PACKAGE__->static( shift );
...
}

sub restrictedmethod {
my $self = __PACKAGE__->restricted( shift );
...
}

sub abstractmethod { __PACKAGE__->abstract }

1;

...

my $obj = My::Class->new( public_attr => fish );

MOTIVATION

One of Perls greatest strengths is its flexible object model. You can turn anything (so long as its a reference, or you can get a reference to it) into an object. This allows coders to choose the most appropriate implementation for each specific need, and still maintain a consistent object oriented approach.
A common paradigm for implementing objects in Perl is to use a blessed hash reference, where the keys of the hash represent attributes of the class. This approach is simple, relatively quick, and trivial to extend, but its not very secure. Since we return a reference to the hash directly to the user they can alter hash values without using the classs accessor methods. This allows for coding "short-cuts" which at best reduce the maintainability of the code, and at worst may introduce bugs and inconsistencies not anticipated by the original module author.

On some systems, this may not be too much of a problem. If the developer base is small, then we can trust the users of our modules to Do The Right Thing. However, as a modules user base increases, or the complexity of the systems our modules are embedded in grows, it may become desirable to control what users can and cant access in our module to guarantee our codes behaviour. A traditional method of indicating that an objects data and methods are for internal use only is to prefix attribute and method names with underscores. However, this still relies on the end user Doing The Right Thing.

Class::Declare provides mechanisms for module developers to explicitly state where and how their class attributes and methods may be accessed, as well as hiding the underlying data store of the objects to prevent unwanted tampering with the data of the objects and classes. This provides a robust framework for developing Perl modules consistent with more strongly-typed object oriented languages, such as Java and C++, where classes provide public, private, and protected interfaces to object and class data and methods.

<<less
Download (0.075MB)
Added: 2007-06-20 License: Perl Artistic License Price:
856 downloads
Class::Adapter 1.02

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.

<<less
Download (0.024MB)
Added: 2007-06-20 License: Perl Artistic License Price:
856 downloads
Class::Spiffy 0.15

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.

<<less
Download (0.024MB)
Added: 2007-06-19 License: Perl Artistic License Price:
857 downloads
Class::StrongSingleton 0.02

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.

<<less
Download (0.006MB)
Added: 2007-06-19 License: Perl Artistic License Price:
858 downloads
Secleted [ 0 ] software to compare
  • Page: 1 of 5
  • 1
  • 2
  • 3
  • 4
  • 5