NAME

Bric::Dist::Action - Interface to actions that can be performed on resources for given server types.

VERSION

$Revision: 1.7 $

DATE

$Date: 2002/03/14 01:18:06 $

SYNOPSIS

use Bric::Dist::Action;

# Constructors.
# Create a new object.
my $action = Bric::Dist::Action->new;
# Look up an existing object. May return a subclass of Bric::Dist::Action.
$action = Bric::Dist::Action->lookup({ id => 1 });
# Get a list of action objects.
my @servers = Bric::Dist::Action->list({ type => 'Akamaize' });

# Class methods.
# Get a list of object IDs.
my @st_ids = Bric::Dist::Action->list_ids({ type => 'Akamaize' });
# Get an introspection hashref.
my $int = Bric::Dist::Action->my_meths;
my $bool = Bric::Dist::Action->has_more;

# Instance Methods.
my $id = $action->get_id;
my $type = $action->get_type;
# Changing the type will likely change the $action to a different subclass,
# and will delete any attributes associated with the previous type.
$action = $action->set_type($type);

# Description is only available for types that have been looked up in the
# database.
my $description = $action->get_description;

# The server type designation may be changed at will.
my $st_id = $action->get_server_type_id;
my $action = $action->set_server_type_id($st_id);

# The list of MEDIA types can only be fetched on existing actions. The list
# of MEDIA types is dependent on the type of action.
my @medias = $action->get_media_types;
my $medias = $action->get_media_href;

# Perform the action.
$action->do_it($job, $server_type);

# Delete the action.
$action->del

# Save the action.
$action->save;

DESCRIPTION

This class manages the actions that are applied for a given server type to the files associated with a given job. The idea is that for any given server type, an ordered list of actions will be performed whenever a job is executed for that server type. For example, if there is a server type "Production Server", the list of actions (represented as Bric::Dist::Action objects) for that server type might be "Akamaize", "Ultraseek", "Gzip", and "Put". When a job (represented by a Bric::Dist::Job object) is executed for that server group, then each of those actions will be instantiated in turn, and their do_it() methods called on the job's resources.

The types of actions available to customers are created at development time, and are represented both in the database and by subclasses of Bric::Dist::Action. They can be changed and reordered for a given servery type via the Bric::Dist::ServerType interface. So Bric::Dist::Action will frequently not be accessed directly, but via Bric::Dist::ServerType accessors.

INTERFACE

Constructors

my $act = Bric::Dist::Action->new($init)

Instantiates a Bric::Dist::Action object. An anonymous hash of initial values may be passed. The supported initial value keys are:

The active property will be set to true by default. Call $act->save() to save the new object.

Throws:

Side Effects: NONE.

Notes: NONE.

my $act = Bric::Dist::Action->lookup({ id => $id })

Looks up and instantiates a new Bric::Dist::Action object based on the Bric::Dist::Action object ID passed. If $id is not found in the database, lookup() returns undef.

Throws:

Side Effects: If $id is found, populates the new Bric::Dist::Action object with data from the database before returning it.

Notes: NONE.

my (@acts || $acts_aref) = Bric::Dist::Action->list($params)

Returns a list or anonymous array of Bric::Dist::Action objects based on the search parameters passed via an anonymous hash. The supported lookup keys are:

Throws:

Side Effects: Populates each Bric::Dist::Action object with data from the database before returning them all.

Notes: NONE.

my $actions_href = Bric::Dist::Action->href($params)

Returns an anonymous hash of Bric::Dist::Action objects, where the keys are the object IDs and the values are the objects themselves, based on the search parameters passed via an anonymous hash. The supported lookup keys are the same as for list().

Throws:

Side Effects: Populates each Bric::Dist::Action object with data from the database before returning them all.

Notes: NONE.

Destructors

$act->DESTROY

Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Public Class Methods

Public Instance Methods

my $id = $act->get_id

Returns the ID of the Bric::Dist::Action object.

Throws:

Side Effects: NONE.

Notes: If the Bric::Dist::Action object has been instantiated via the new() constructor and has not yet been saved, the object will not yet have an ID, so this method call will return undef.

my $type = $act->get_type
my $type = $act->get_name

Returns the type of the action, e.g., "FTP" or "Akamaize."

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $act->set_type($type)

Sets the type of the action. The type must be the type of a supported action. Call Bric::Dist::Action->list_types() to get a list of supported actions.

Throws:

Side Effects: NONE.

Notes: NONE.

my $order = $act->get_ord

Returns the number representing this action's place in the order of execution for all the actions associated with the server_type_id with which this action is associated.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $act->set_ord($order)

Sets the order of the action. This number represents where in the sequence of actions associated with the server_type_id with which this action is associated that this action will be executed. If this property is never set on a new action, then the order will default to the last in the sequence of actions. If it is set, and it comes before other, pre-existing actions, those actions will be shifted down in the list of actions.

Throws:

Side Effects: NONE.

Notes: NONE.

my $description = $act->get_description

Returns the description of the action.

Throws:

Side Effects: NONE.

Notes: NONE.

my $server_type_id = $act->get_server_type_id

Returns the ID of the Bric::Dist::ServerType object for which this action will be performed.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $act->set_server_type_id($server_type_id)

Associates this action with a Bric::Dist::ServerType object so that this action can be performed for servers of that type.

Throws:

Side Effects: NONE.

Notes: NONE.

my (@medias || $medias_aref) = $action->get_media_types

Returns a list or anonymous array of the MEDIA types that apply to this action. Returns an empty list (or undef in a scalar context) if this action applies to all MEDIA types.

Throws:

Side Effects: NONE.

Notes: NONE.

my (@medias || $medias_aref) = $action->get_media_href

Returns an anonymous hash of the MEDIA types that apply to this action. Returns undef if this action applies to all MEDIA types.

Throws:

Side Effects: NONE.

Notes: NONE.

$action = $action->del

Marks the Bric::Dist::Action object to be deleted from the database. Call $action->save to actually finish it off.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $action->activate

Activates the Bric::Dist::Action object. Call $action->save to make the change persistent. Bric::Dist::Action objects instantiated by new() are active by default.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $action->deactivate

Deactivates (deletes) the Bric::Dist::Action object. Call $action->save to make the change persistent.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $action->is_active

Returns $self if the Bric::Dist::Action object is active, and undef if it is not.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $act->save

Saves any changes to the Bric::Dist::Action object. Returns $self on success and undef on failure.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $act->do_it($job)

Performs the action on the resources associated with $job. Must be overridden in Bric::Dist::Action subclasses.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $act->undo_it($job)

Undoes the action on the resources associated with $job. Here is is actually a no-op that returns false, but when overridden, it should return true, as Bric::Dist::Job uses this return value to determine whether or not to log an event.

Throws:

Side Effects: NONE.

Notes: NONE.

PRIVATE

Private Class Methods

NONE.

Private Instance Methods

my $attr = $action->_get_attr

Used by subclasses to access an action's Bric::Util::Attribute::Action object.

Throws:

Side Effects: NONE.

Notes: NONE.

$action = $action->_clear_attr

A No-op function that may be overridden in subclasses with attributes. It is called by set_type() above so that subclasses of Bric::Dist::Action can clear their attributes before the Bric::Dist::Action object is blessed into a different class. See Bric::Dist::Action::Akamaize for an example.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Private Functions

my $act_aref = &$get_em( $pkg, $params )
my $act_ids_aref = &$get_em( $pkg, $params, 1 )

Function used by lookup() and list() to return a list of Bric::Dist::Action objects or, if called with an optional third argument, returns a listof Bric::Dist::Action object IDs (used by list_ids()).

Throws:

Side Effects: NONE.

Notes: NONE.

my $action = &$make_obj( $pkg, $init )

Instantiates a Bric::Dist::Action object. Used by &$get_em().

Throws:

Side Effects: NONE.

Notes: NONE.

my $bool = &$reorder( $server_type_id, $from_ord, $to_ord )

Reorders the list of actions for a given server_type_id. Pass in the server_type_id and the ordinal number to change from to the ordinal number to change to. The action that was number $from_ord will be changed to number $to_ord, and the order of the other actions will be shifted to accommodate it. For example, if you had the following actions:

Order  ID  Action
-----  --  ------------------
    1  11  Clean HTML
    2  12  Akamaize
    3  13  Move
    4  14  Go Home

To change the order so that "Akamaize" precedes "Clean HTML", call this function like so:

&$reorder(12, 2, 1);

And the Data will be reordered in this manner:

Order  ID  Action
-----  --  ------------------
    1  12  Akamaize
    2  11  Clean HTML
    3  13  Move
    4  14  Go Home

Throws:

Side Effects: NONE.

Notes: NONE.

NOTES

NONE.

AUTHOR

David Wheeler <david@wheeler.net>

SEE ALSO

Bric

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 418:

=back doesn't take any parameters, but you said =back 4

Around line 444:

You can't have =items (as at line 448) unless the first thing after the =over is an =item

Around line 659:

Expected '=item *'

Around line 661:

Expected '=item *'

Around line 663:

Expected '=item *'

Around line 665:

Expected '=item *'

Around line 667:

Expected '=item *'

Around line 669:

Expected '=item *'

Around line 671:

Expected '=item *'

Around line 1407:

=back doesn't take any parameters, but you said =back 4