Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 29.542.303 Times

Class::Observable 1.04

  Date Added: January 13, 2010  |  Visits: 633

Class::Observable

Report Broken Link
Printer Friendly Version


Product Homepage
Download (79 downloads)



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.

Requirements: No special requirements
Platforms: Linux
Keyword: Action Brush Class Classobservable Libraries Object Observer Perl Module Programming Sub
Users rating: 0/10

License: Freeware Size: 10.24 KB
USER REVIEWS
More Reviews or Write Review


CLASS::OBSERVABLE RELATED
Libraries  -  Class::Std::Storable 0.0.1
Class::Std::Storable is a Perl module to support for creating serializable "inside-out" classes. SYNOPSIS In general, use this class exactly as you would Class::Std. package Ice::Cream; use Class::Std::Storable; { my %name_of :ATTR( :get...
8.19 KB  
Libraries  -  Class::Meta::Declare 0.04
Class::Meta::Declare is a Perl module deprecated in favor of Class::Meta::Express. SYNOPSIS This was a first attempt at making a saner interface for Class::Meta. It is nicer, but Class::Meta::Express is nicer still. Go use that one. package...
15.36 KB  
Libraries  -  Class::Std::Utils 0.0.2
Class::Std::Utils is a Perl module for utility subroutines for building "inside-out" objects. SYNOPSIS use Class::Std::Utils; # Constructor for anonymous scalars... my $new_object = bless anon_scalar(), $class; # Convert an object...
5.12 KB  
Libraries  -  Class::DBI::FormBuilder 0.481
Class::DBI::FormBuilder is a Perl module with Class::DBI/CGI::FormBuilder integration. SYNOPSIS package Film; use strict; use warnings; use base Class::DBI; use Class::DBI::FormBuilder; # for indented output: # use...
46.08 KB  
Libraries  -  Class::Meta::Express 0.04
Class::Meta::Express is a Perl module for concise, expressive creation of Class::Meta classes. Synopsis package My::Contact; use Class::Meta::Express; class { meta contact => ( default_type => string ); has name; has contact => (...
9.22 KB  
Libraries  -  Class::Meta::Type 0.53
Class::Meta::Type is a Perl module for data type validation and accessor building. SYNOPSIS package MyApp::TypeDef; use strict; use Class::Meta::Type; use IO::Socket; my $type = Class::Meta::Type->add( key => io_socket, desc =>...
61.44 KB  
Libraries  -  Class::Declare::Attributes 0.04
Class::Declare::Attributes is a Perl module with Class::Declare method types using Perl attributes. SYNOPSIS package My::Class; use 5.006; use strict; use warnings; use base qw( Class::Declare::Attributes ); # declare the...
21.5 KB  
Libraries  -  Class::Method::hash 2.08
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; #...
89.09 KB  
Libraries  -  DBIx::Class::Manual::Cookbook 0.08001
DBIx::Class::Manual::Cookbook is a Perl module that contains miscellaneous recipes. Paged results When you expect a large number of results, you can ask DBIx::Class for a paged resultset, which will fetch only a small number of records at a...
286.72 KB  
Libraries  -  Class::Adapter::Builder 1.02
Class::Adapter::Builder is a Perl module that can generate Class::Adapter classes. SYNOPSIS package My::Adapter; use strict; use Class::Adapter::Builder ISA => Specific::API, METHODS => [ qw{foo bar baz} ], method => different_method;...
24.58 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by freedesktop.org, it is used to describe information about an application such as the name and...
327.68 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB  
Libraries  -  App::SimpleScan::Substitution::Line 2.02
App::SimpleScan::Substitution::Line is a line with optional fixed variable values. SYNOPSIS my $line = App::SimpleScan::Substitution::Line->new(" this "); # Use only this value when substituting " ". $line->fix(substituite =>...
54.27 KB