Bric::Dist::Action - Interface to actions that can be performed on resources for given server types.
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;
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::Util::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 server type via the Bric::Dist::ServerType interface. So Bric::Dist::Action will frequently not be accessed directly, but via Bric::Dist::ServerType accessors.
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.
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.
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:
Action ID. May use ANY for a list of possible values.
The ID of an action type. May use ANY for a list of possible values.
The name of an action type. May use ANY for a list of possible values.
The ID of a destination (server type) with which actions may be associated. May use ANY for a list of possible values.
An action type description. May use ANY for a list of possible values.
Throws:
Side Effects: Populates each Bric::Dist::Action object with data from the database before returning them all.
Notes: NONE.
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.
Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.
Throws: NONE.
Side Effects: NONE.
Notes: NONE.
Returns the next ordinal number in the sequence of actions for a given server_type_id.
Throws:
Side Effects: NONE.
Notes: NONE.
Returns a list or anonymous array of Bric::Dist::Action object IDs based on the search criteria passed via an anonymous hash. The supported lookup keys are the same as those for list().
Throws:
Side Effects: NONE.
Notes: NONE.
Returns a list or anonymous array of the types of the supported actions.
Throws: NONE.
Side Effects: NONE.
Notes: NONE.
Returns true if the action has more properties than does the base class (Bric::Dist::Action), and false if not. Here in Bric::Dist::Action it returns false, so it only needs to be overridden to return true in subclasses of Bric::Dist::Action that contain extra properties (such as Bric::Dist::Action::Akamaize).
Throws: NONE.
Side Effects: NONE.
Notes: NONE.
Returns an anonymous hash of introspection data for this object. If called with a true argument, it will return an ordered list or anonymous array of introspection data. If a second true argument is passed instead of a first, then a list or anonymous array of introspection data will be returned for properties that uniquely identify an object (excluding id, which is assumed).
Each hash key is the name of a property or attribute of the object. The value for a hash key is another anonymous hash containing the following keys:
The name of the property or attribute. Is the same as the hash key when an anonymous hash is returned.
The display name of the property or attribute.
A reference to the method that will retrieve the value of the property or attribute.
An anonymous array of arguments to pass to a call to get_meth in order to retrieve the value of the property or attribute.
A reference to the method that will set the value of the property or attribute.
An anonymous array of arguments to pass to a call to set_meth in order to set the value of the property or attribute.
The type of value the property or attribute contains. There are only three types:
If the value is a 'short' value, this hash key contains the length of the field.
The property is searchable via the list() and list_ids() methods.
The property or attribute is required.
An anonymous hash of properties used to display the property or attribute. Possible keys include:
The display field type. Possible values are
The Length, in letters, to display a text or password field.
The maximum length of the property or value - usually defined by the SQL DDL.
The number of rows to format in a textarea field.
The number of columns to format in a textarea field.
An anonymous hash of key/value pairs representing the values and display names to use in a select list.
Throws: NONE.
Side Effects: NONE.
Notes: NONE.
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.
Returns the type of the action, e.g., "FTP" or "Akamaize."
Throws:
Side Effects: NONE.
Notes: NONE.
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.
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.
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.
Returns the description of the action.
Throws:
Side Effects: NONE.
Notes: NONE.
Returns the ID of the Bric::Dist::ServerType object for which this action will be performed.
Throws:
Side Effects: NONE.
Notes: NONE.
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.
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.
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.
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.
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.
Deactivates (deletes) the Bric::Dist::Action object. Call $action->save to make the change persistent.
Throws:
Side Effects: NONE.
Notes: NONE.
Returns $self if the Bric::Dist::Action object is active, and undef if it is not.
Throws:
Side Effects: NONE.
Notes: NONE.
Saves any changes to the Bric::Dist::Action object. Returns $self on success and undef on failure.
Throws:
Side Effects: NONE.
Notes: NONE.
Performs the action on the resources associated with $job. Must be overridden in Bric::Dist::Action subclasses.
Throws:
Side Effects: NONE.
Notes: NONE.
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::Util::Job uses this return value to determine whether or not to log an event.
Throws:
Side Effects: NONE.
Notes: NONE.
Protected method called by action subclasses at startup time so they can register themselves as available actions. Some may wish to not register themselves under certain circumstances. For example, Bric::Dist::Action::DTDValidate should only be registered if XML::LibXML has been installed. Thus that class only registers itself if XML::LibXML does not load.
Throws: NONE.
Side Effects: NONE.
Notes: NONE.
Used by subclasses to access an action's Bric::Util::Attribute::Action object.
Throws:
Side Effects: NONE.
Notes: NONE.
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.
Called by set_type() to rebless an action into a new class. Useful for for subclasses to override in order to set default values on attributes, such as they would typically do in new().
Throws: NONE.
Side Effects: NONE.
Notes: NONE.
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 list of Bric::Dist::Action object IDs (used by list_ids()).
Throws:
Side Effects: NONE.
Notes: NONE.
Instantiates a Bric::Dist::Action object. Used by &$get_em().
Throws:
Side Effects: NONE.
Notes: NONE.
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.
__PACKAGE__->_register_action($key) to register your action subclass._register_action(). If your action can act on files of any type, add one record to the action_type__media_type table with the media_type__id column set to 0, which corresponds to no (and therefore all) media types.make devtest to make sure that all tests pass.use statement for your new action to Bric::App::Handler.NONE.
David Wheeler