| Pangloss documentation | Contained in the Pangloss distribution. |
Pangloss::Application::Base - base class for application objects.
# abstract class - cannot be used directly
use base qw( Pangloss::Application::Base );
sub foo {
my $self = shift;
$self->parent;
$self->store;
my $obj = $self->get_or_create_stored_obj( $key, $class );
$self->save( $obj );
}
This is a base class for all application objects.
set/get the parent application.
set/get the parent's store.
gets or creates an object bound to $key from the store. calls $class->new and stores the result if no object is found in the store.
save this object in the store.
Steve Purkis <spurkis@quiup.com>
| Pangloss documentation | Contained in the Pangloss distribution. |
package Pangloss::Application::Base; use strict; use warnings::register; use Error; use Pangloss::Users; use base qw( Pangloss::Object ); use accessors qw( parent ); our $VERSION = ((require Pangloss::Version), $Pangloss::VERSION)[1]; our $REVISION = (split(/ /, ' $Revision: 1.4 $ '))[2]; sub store { my $self = shift; $self->parent->store(@_); } sub get_or_create_stored_obj { my $self = shift; my $key = shift; my $class = shift; my $obj = $self->store->get_object_named( $key ); unless ($obj) { $obj = $class->new(); $self->store->insert( $obj ); $self->store->bind_name( $key => $obj ); } return $obj; } sub save { my $self = shift; my $obj = shift; $self->store->insert( $obj ); } 1; __END__ #------------------------------------------------------------------------------