NAME

Bric - The Bricolage base class.

VERSION

Release Version: 1.6.14

File (CVS) Version:

$Revision: 1.35.2.23 $

DATE

$Date: 2004/04/11 15:30:41 $

SYNOPSIS

use base qw( Bric );

DESCRIPTION

The Bric class is an abstract class should never be used directly. Instead new classes should be derived from it.

METHODS

Constructors

$self = Bric->new($init)

Call this constructor from all derived classes. This sets up some basic fields and methods.

Throws:

NONE

Side Effects

NONE

Notes:

NONE

my $obj = __PACKAGE__->lookup({ id => $obj_id })

This method is similar to the 'new' method except it is used only to retrieve a already existing object of this type from the database whereas 'new' creates a new, empty object. All subclasses should override this method in order to look up their objects in the database. However, they must first call cache_lookup() to see if it can retrieve the object from the cache. If they can, they should simply return the object. Otherwise, once they look up the object in the database, they should cache it via the cache_me() method. For example:

sub lookup {
    my $pkg = shift;
    my $self = $pkg->cache_lookup(@_);
    return $self if $self;
    # ... Continue to look up object in the database. Then...
    $self->cache_me;
}

Throws:

Side Effects NONE.

Notes: NONE.

my $obj = __PACKAGE__->cache_lookup({ id => $obj_id })

Looks up an object in the cache and returns it if it exists. Otherwise it returns an undefined value. This method is meant to be used by Bric subclasses in their lookup() methods. See lookup() for an example.

Throws: NONE.

Side Effects NONE.

Notes: NONE.

my @objs = __PACKAGE__->list($params)

This is an abstract method. All derived classes should override this method. In the concrete implementations of this method, classes should also call cache_me() for every object to be returned.

Throws:

Side Effects NONE.

Notes: NONE.

Public Class Methods

my @ids = __PACKAGE__->list_ids($params)

This is an abstract method. All derived classes should override this method. This method returns a list of IDs rather than objects.

Throws:

Side Effects NONE.

Notes: NONE.

Bric::register_fields({'field1' => Bric::FIELD_READ, ...})

This function is used by sub classes to register their field names and assign access levels to them.

Throws:

Side Effects: Defines a subroutine named ACCESS() in the caller's package.

Notes: NONE.

Destructors

$job->DESTROY

This is the default destructor method. Even if nothing is defined within it, it should still be here so that Perl wont waste time trying to find it in the AUTOLOAD section.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

die "...";

Uses confess rather than die to report errors.

Throws:

Its a 'thrower'.

Side Effects

Halts program execution

Notes:

warn "...";

Uses cluck rather than warn to output warnings.

Throws:

Its a 'thrower'.

Side Effects

Outputs a warning message

Notes:

Private Class Methods

NONE.

Public Instance Methods

$val = $obj->get_field
$obj = $obj->set_field

This is the AUTOLOAD handler. It translates all set and get operations into subroutines acting upon the fields in derived classes.

Throws:

Side Effects

Creates a custom subroutine reference in the calling packages namespace

Notes:

$ids = $obj->get_grp_ids || $pkg->get_grp_ids;

Return a list of IDs for the Bric::Util::Grp objects to which the object belongs. When called as a class method, return the value of the class' INSTANCE_GROUP_ID constant.

Throws:

NONE

Side Effects:

NONE

Notes:

NONE

$obj = $obj->cache_me;

Caches the object for later retrieval by the lookup() class method. Should be called for all object retrieved from the database. That includes all objects to be returned by lookup(), list(), and href() methods.

Throws: NONE.

Side Effects NONE.

Notes: NONE.

$success = $obj->register_instance();

Add the current object to the appropriate group in the database. These are groups that contain every instance of a particular type of object.

Throws:

NONE

Side Effects:

NONE

Notes:

NONE

$success = $obj->unregister_instance();

Add the current object to the appropriate group in the database. These are groups that contain every instance of a particular type of object.

Throws:

NONE

Side Effects:

NONE

Notes:

NONE

$success = $obj->save();

Save the current object to the database.

Throws:

NONE

Side Effects:

NONE

Notes:

NONE

Private Instance Methods

$obj->_get__dirty()
$obj->_set__dirty()

Get and set the _dirty field

Throws: NONE.

Side Effects NONE.

Notes: NONE.

$obj = $obj->_set(\%keyvals);
$obj = $obj->_set(\@keys, \@values);

The internal function used to set field values. Can be called with either a hash reference of keys and their corresponding values, or as two array references, one containing all the keys, the other containing all the values

Throws:

Side Effects NONE.

Notes: NONE.

@vals || $val = $obj->_get(@keys);

The internal function used to get field values. It accepts a list of key values to retrieve from the object.

Throws:

Problems retrieving field 'foo'

Side Effects

NONE

Notes:

Error checking and exception throwing is only performed in QA_MODE for performance reasons.

$vals = $obj->_get_ref(@keys);

The internal function used to get field values and return them as an arrayref. It accepts a list of key values to retrieve from the object.

Throws:

NONE

Side Effects

NONE

Notes:

AUTHOR

Garth Webb <garth@perijove.com>

Sam Tregar <stregar@about-inc.com>

COPYRIGHT AND LICENSE

Copyright (c) 2001 About.com. Changes Copyright (c) 2002-2003 Kineticode, Inc. and others. See Bric::License for complete license terms and conditions.