Class::Observable 1.04
Sponsored Links
Class::Observable 1.04 Ranking & Summary
File size:
0.010 MB
Platform:
Any Platform
License:
Perl Artistic License
Price:
Downloads:
870
Date added:
2007-06-06
Publisher:
Chris Winters
Class::Observable 1.04 description
Class::Observable is a Perl module that allows other classes and objects to respond to events in yours.
SYNOPSIS
# Define an observable class
package My::Object;
use base qw( Class::Observable );
# Tell all classes/objects observing this object that a state-change
# has occurred
sub create {
my ( $self ) = @_;
eval { $self->_perform_create() };
if ( $@ ) {
My::Exception->throw( "Error saving: $@" );
}
$self->notify_observers();
}
# Same thing, except make the type of change explicit and pass
# arguments.
sub edit {
my ( $self ) = @_;
my %old_values = $self->extract_values;
eval { $self->_perform_edit() };
if ( $@ ) {
My::Exception->throw( "Error saving: $@" );
}
$self->notify_observers( edit, old_values => %old_values );
}
# Define an observer
package My::Observer;
sub update {
my ( $class, $object, $action ) = @_;
unless ( $action ) {
warn "Cannot operation on [", $object->id, "] without action";
return;
}
$class->_on_save( $object ) if ( $action eq save );
$class->_on_update( $object ) if ( $action eq update );
}
# Register the observer class with all instances of the observable
# class
My::Object->add_observer( My::Observer );
# Register the observer class with a single instance of the
# observable class
my $object = My::Object->new( foo );
$object->add_observer( My::Observer );
# Register an observer object the same way
my $observer = My::Observer->new( bar );
My::Object->add_observer( $observer );
my $object = My::Object->new( foo );
$object->add_observer( $observer );
# Register an observer using a subroutine
sub catch_observation { ... }
My::Object->add_observer( &catch_observation );
my $object = My::Object->new( foo );
$object->add_observer( &catch_observation );
# Define the observable class as a parent and allow the observers to
# be used by the child
package My::Parent;
use strict;
use base qw( Class::Observable );
sub prepare_for_bed {
my ( $self ) = @_;
$self->notify_observers( prepare_for_bed );
}
sub brush_teeth {
my ( $self ) = @_;
$self->_brush_teeth( time => 45 );
$self->_floss_teeth( time => 30 );
$self->_gargle( time => 30 );
}
sub wash_face { ... }
package My::Child;
use strict;
use base qw( My::Parent );
sub brush_teeth {
my ( $self ) = @_;
$self->_wet_toothbrush();
}
sub wash_face { return }
# Create a class-based observer
package My::ParentRules;
sub update {
my ( $item, $action ) = @_;
if ( $action eq prepare_for_bed ) {
$item->brush_teeth;
$item->wash_face;
}
}
My::Parent->add_observer( __PACKAGE__ );
$parent->prepare_for_bed # brush, floss, gargle, and wash face
$child->prepare_for_bed # pretend to brush, pretend to wash face
SYNOPSIS
# Define an observable class
package My::Object;
use base qw( Class::Observable );
# Tell all classes/objects observing this object that a state-change
# has occurred
sub create {
my ( $self ) = @_;
eval { $self->_perform_create() };
if ( $@ ) {
My::Exception->throw( "Error saving: $@" );
}
$self->notify_observers();
}
# Same thing, except make the type of change explicit and pass
# arguments.
sub edit {
my ( $self ) = @_;
my %old_values = $self->extract_values;
eval { $self->_perform_edit() };
if ( $@ ) {
My::Exception->throw( "Error saving: $@" );
}
$self->notify_observers( edit, old_values => %old_values );
}
# Define an observer
package My::Observer;
sub update {
my ( $class, $object, $action ) = @_;
unless ( $action ) {
warn "Cannot operation on [", $object->id, "] without action";
return;
}
$class->_on_save( $object ) if ( $action eq save );
$class->_on_update( $object ) if ( $action eq update );
}
# Register the observer class with all instances of the observable
# class
My::Object->add_observer( My::Observer );
# Register the observer class with a single instance of the
# observable class
my $object = My::Object->new( foo );
$object->add_observer( My::Observer );
# Register an observer object the same way
my $observer = My::Observer->new( bar );
My::Object->add_observer( $observer );
my $object = My::Object->new( foo );
$object->add_observer( $observer );
# Register an observer using a subroutine
sub catch_observation { ... }
My::Object->add_observer( &catch_observation );
my $object = My::Object->new( foo );
$object->add_observer( &catch_observation );
# Define the observable class as a parent and allow the observers to
# be used by the child
package My::Parent;
use strict;
use base qw( Class::Observable );
sub prepare_for_bed {
my ( $self ) = @_;
$self->notify_observers( prepare_for_bed );
}
sub brush_teeth {
my ( $self ) = @_;
$self->_brush_teeth( time => 45 );
$self->_floss_teeth( time => 30 );
$self->_gargle( time => 30 );
}
sub wash_face { ... }
package My::Child;
use strict;
use base qw( My::Parent );
sub brush_teeth {
my ( $self ) = @_;
$self->_wet_toothbrush();
}
sub wash_face { return }
# Create a class-based observer
package My::ParentRules;
sub update {
my ( $item, $action ) = @_;
if ( $action eq prepare_for_bed ) {
$item->brush_teeth;
$item->wash_face;
}
}
My::Parent->add_observer( __PACKAGE__ );
$parent->prepare_for_bed # brush, floss, gargle, and wash face
$child->prepare_for_bed # pretend to brush, pretend to wash face
Class::Observable 1.04 Screenshot
Class::Observable 1.04 Keywords
Observable 1.04
To Respond To
module that allows
Classes and Objects
to events
to respond
respond to
Perl module
in yours
Events In
observer
Self-
sub
object
class
action
Bookmark Class::Observable 1.04
Class::Observable 1.04 Copyright
WareSeeker periodically updates pricing and software information of Class::Observable 1.04 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of Class::Observable 1.04 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed
Featured Software
Want to place your software product here?
Please contact us for consideration.
Contact WareSeeker.com
Related Information
how to respond to a summons
how to respond to interview questions
ways to respond to literature
etiquette to respond to an rsvp
how to respond to a wedding invitation
how to respond to a civil lawsuit
how to respond to a complaint
how did fdr respond to the great depression
object lessons
observer reporter newspaper
how to respond to the silent treatment
hidden object games
charlotte observer
how to respond to rsvp
objectives for resumes
observer radio
appropriate ways to behave and respond in
how to respond to a complaint letter
Related Software
Class::Contract - Design-by-Contract OO in Perl. Free Download
Class::Meta::Declare is a Perl module deprecated in favor of Class::Meta::Express. Free Download
Class::Simple is a simple Object-Oriented Base Class. Free Download
Class::Declare is a Perl module created to declare classes with public, private and protected attributes and methods. Free Download
Class::Adapter is a Perl implementation of the "Adapter" Design Pattern. Free Download
Class::Classless is a Perl framework for classless OOP. Free Download
Class::Meta::Express is a Perl module for concise, expressive creation of Class::Meta classes. Free Download
Class::StrongSingleton is a stronger and more secure Singleton base class. Free Download
Latest Software
Popular Software
Favourite Software