Pangloss::Application::Base - base class for application objects.


Pangloss documentation Contained in the Pangloss distribution.

Index


Code Index:

NAME

Top

Pangloss::Application::Base - base class for application objects.

SYNOPSIS

Top

  # 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 );
  }

DESCRIPTION

Top

This is a base class for all application objects.

METHODS

Top

$obj->parent

set/get the parent application.

$obj->store

set/get the parent's store.

$abc = $obj->get_or_create_stored_obj( $key, $class )

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.

$obj->save( $abc )

save this object in the store.

AUTHOR

Top

Steve Purkis <spurkis@quiup.com>

SEE ALSO

Top

Pangloss::Application


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__

#------------------------------------------------------------------------------