Bric::Dist::ServerType(3p)

NAME
Bric::Dist::ServerType - Interface for managing types of servers to which to distribute content.

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2006-03-18 01:26:34 +0100 (Sat, 18 Mar 2006) $

SYNOPSIS
  use Bric::Dist::ServerType;

  # Constructors.
  # Create a new object.
  my $st = Bric::Dist::ServerType->new;
  # Look up an existing object.
  $st = Bric::Dist::ServerType->lookup({ id => 1 });
  # Get a list of server type objects.
  my @sts = Bric::Dist::ServerType->list({ move_method => 'FTP Transport' });
  # Get an anonymous hash of server type objects.
  my $sts_href = Bric::Dist::ServerType->href({ description => 'Preview%' });

  # Class methods.
  # Get a list of object IDs.
  my @st_ids = Bric::Dist::ServerType->list_ids({ description => 'Prev%' });
  # Get an introspection hashref.
  my $int = Bric::Dist::ServerType->my_meths;
  # Get a list of mover types.
  my @move_methods = Bric::Dist::ServerType->list_move_methods;

  # Instance Methods.
  my $id = $st->get_id;
  my $name = $st->get_name;
  $st = $st->set_name($name);
  my $description = $st->get_description;
  $st = $st->set_description($description);
  my $move_method = $st->get_move_method;
  $st = $st->set_move_method($move_method);
  my $site_id = $st->get_site_id;
  $st = $st->set_site_id($site_id);
  print "ST is ", $st->can_copy ? '' : 'not ', "copyable.\n";
  $st->copy;
  $st->no_copy;

  print "ST ", $st->can_publish ? 'publishes' : "does not publish.\n";
  $st = $st->on_publish; # Used for publish event.
  $st = $st->no_publish; # Not used for publish event.

  print "ST ", $st->can_preview ? 'previews' : "does not preview.\n";
  $st = $st->on_preview; # Used for preview event.
  $st = $st->no_preview; # Not used for preview event.

  print "ST is ", $st->is_active ? '' : 'not ', "active.\n";
  $st->deactivate;
  $st->activate;

  # Accessors to servers of this type.
  my @servers = $st->get_servers;
  my $server = $st->new_server;
  $st->del_servers;

  # Accessors to output channels associated with this server type.
  my @ocs = $st->get_output_channels;
  $st = $st->add_output_channels(@ocs);
  $st = $st->del_output_channels(@ocs);

  # Accessors to actions associated with this type.
  my @actions = $st->get_actions;
  my $action = $st->new_action;
  $st->del_actions;

  # Save it.
  $st->save;

DESCRIPTION
This class manages types of servers. A server type represents a class of servers on which a list of actions should be performed upon the execution of a job. A server type, therefore, simply describes a list of servers for which the actions will be performed and a list of actions to be executed on the files associated with a given job. The last action should be a move statement, to move each file to each of the servers.

So use this class a the central management point for figuring out what happens to files, and in what order, and what servers they are sent to, in the event of a publish or preview event.

INTERFACE

  Constructors

my $st = Bric::Dist::ServerType->new($init)
    Instantiates a Bric::Dist::ServerType object. An anonymous hash of initial values may be passed. The supported initial value keys are:

    •   name

    •   description

    •   site_id

    •   move_method

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

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

my $st = Bric::Dist::ServerType->lookup({ id => $id })
my $st = Bric::Dist::ServerType->lookup({ name => $name, site_id => $site_id })
    Looks up and instantiates a new Bric::Dist::ServerType object based on the Bric::Dist::ServerType object ID or name and site ID passed. If $id or $name and $site_id is not found in the database, "lookup()" returns "undef".

    Throws:

    •   Too many Bric::Dist::ServerType objects found.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

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

    Notes: NONE.

my (@sts || $sts_aref) = Bric::Dist::ServerType->list($params)
    Returns a list or anonymous array of Bric::Dist::ServerType objects based on the search parameters passed via an anonymous hash. The supported lookup keys are:

    id  Destination ID. May use "ANY" for a list of possible values.

    move_method
        Destination move method. May use "ANY" for a list of possible values.

    name
        Destination name. May use "ANY" for a list of possible values.

    description
        Destination description. May use "ANY" for a list of possible values.

    site_id
        ID of Bric::Biz::Site object with which destinations may be associated. May use "ANY" for a list of possible values.

    job_id
        ID of Bric::Util::Job object with which destinations may be associated. May use "ANY" for a list of possible values.

    output_channel_id
        ID of Bric::Biz::OutputChannel object with which destinations may be associated. May use "ANY" for a list of possible values.

    can_copy
        Boolean value indicating whether resources should be copied to a temporary location before distribution actions should be carried out on them. May use "ANY" for a list of possible values.

    can_publish
        Boolean value indicating whether or not the destination is distributed to upon publish events.

    can_preview
        Boolean value indicating whether or not the destination is distributed to upon preview events.

    grp_id
        ID of Bric::Util::Grp object with which destinations may be associated. May use "ANY" for a list of possible values.

    active
        Boolean value indicating whether the destination object is active.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

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

    Notes: NONE.

my $sts_href = Bric::Dist::ServerType->href($params)
    Returns an anonymous hash of Bric::Dist::ServerType objects, where the keys are object IDs and the values or the objects themselves, based on the search parameters passed via an anonymous hash. The supported lookup keys are are the same as for list().

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

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

    Notes: NONE.

  Destructors

$st->DESTROY
    Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Class Methods

my (@st_ids || $st_ids_aref) = Bric::Dist::ServerType->list_ids($params)
    Returns a list or anonymous array of Bric::Dist::ServerType object IDs based on the search criteria passed via an anonymous hash. The supported lookup keys are the same as those for list().

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

my (@types || $types_aref) = Bric::Dist::ServerType->list_move_methods
    Returns a list or anonymous array of the names of classes that feature a method to move resources.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    Side Effects: NONE.

    Notes: NONE.

$meths = Bric::Dist::ServerType->my_meths
(@meths || $meths_aref) = Bric::Dist::ServerType->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Dist::ServerType->my_meths(0, TRUE)
    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:

    name
        The name of the property or attribute. Is the same as the hash key when an anonymous hash is returned.

    disp
        The display name of the property or attribute.

    get_meth
        A reference to the method that will retrieve the value of the property or attribute.

    get_args
        An anonymous array of arguments to pass to a call to get_meth in order to retrieve the value of the property or attribute.

    set_meth
        A reference to the method that will set the value of the property or attribute.

    set_args
        An anonymous array of arguments to pass to a call to set_meth in order to set the value of the property or attribute.

    type
        The type of value the property or attribute contains. There are only three types:

        short
        date
        blob
    len If the value is a 'short' value, this hash key contains the length of the field.

    search
        The property is searchable via the list() and list_ids() methods.

    req The property or attribute is required.

    props
        An anonymous hash of properties used to display the property or attribute. Possible keys include:

        type
            The display field type. Possible values are

            text
            textarea
            password
            hidden
            radio
            checkbox
            select
        length
            The Length, in letters, to display a text or password field.

        maxlength
            The maximum length of the property or value - usually defined by the SQL DDL.

    rows
        The number of rows to format in a textarea field.

    cols
        The number of columns to format in a textarea field.

    vals
        An anonymous hash of key/value pairs reprsenting the values and display names to use in a select list.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Instance Methods

my $id = $st->get_id
    Returns the ID of the Bric::Dist::ServerType object.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'id' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

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

my $name = $st->get_name
    Returns the server type name.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'name' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->set_name($name)
    Sets the server type name. The name must be unique.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: WRITE access for field 'name' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $description = $st->get_description
    Returns the server type description.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'description' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->set_description($description)
    Sets the server type description.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: WRITE access for field 'description' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $description = $st->get_site_id
    Returns the site ID with which this ServerType is associated.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->set_site_id($site_id)
    Associate this ServerType with a site.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $move_method = $st->get_move_method
    Returns the display name of the Bricolage class responible for moving resources to servers of this type.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'move_method' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->set_move_method($move_method)
    Sets the name of the class responible for moving resources to servers of this type. Get a list of supporte mover types from list_move_methods().

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: WRITE access for field 'move_method' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my (@ocs || $ocs_aref) = $st->get_output_channels
my (@ocs || $ocs_aref) = $st->get_output_channels(@oc_ids)
    Returns a list or anonymous array of the Bric::Biz::OutputChannel objects that represent the directories and/or files on which this server type acts.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

$st = $st->add_output_channels(@ocs)
    Adds Output Channels to this server type. Call save() to save the relationship.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Server internally.

$self = $st->del_output_channels(@ocs)
    Dissociates Output Channels, represented as Bric::Biz::OutputChannel objects, from the server type. call save() to save the dissociations to the database.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

my (@servers || $servers_aref) = $st->get_servers(@server_ids)
    Returns a list or anonymous array of Bric::Dist::Server objects that are of this type. Pass in a list of Bric::Dist::Server object IDs to get back only those Bric::Dist::Server objects. If no IDs are passed, all the Bric::Dist::Server objects of this type will be returned.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Server internally.

my $server = $st->new_server($init)
    Adds a new server to this server type. The initial values for the $init anonymous hash are the same as those for Bric::Dist::Server->new(), although the server_type_id property will be set automatically to associate the new server object with this server type.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Server internally.

$self = $st->del_servers(@server_ids)
    Deletes Bric::Dist::Server objects from this type. Pass in a list of Bric::Dist::Server object IDs to delete only those servers. If no IDs are passed, all of the Bric::Dist::Server objects of this type will be deleted.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Server internally.

my (@actions || $actions_aref) = $st->get_actions(@action_ids)
    Returns a list or anonymous array of Bric::Dist::Action objects that are of this type. Pass in a list of Bric::Dist::Action object IDs to get back only those Bric::Dist::Action objects. If no IDs are passed, all the Bric::Dist::Action objects of this type will be returned.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Action internally.

my $action = $st->new_action($init)
    Adds a new action to this action type. The initial values for the $init anonymous hash are the same as those for Bric::Dist::Action->new(), although the server_type_id property will be set automatically to associate the new action object with this server type.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Action internally.

$self = $st->del_actions(@action_ids)
    Deletes Bric::Dist::Action objects from this type. Pass in a list of Bric::Dist::Action object IDs to delete only those actions. If no IDs are passed, all of the Bric::Dist::Action objects of this type will be deleted.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    Side Effects: NONE.

    Notes: Uses Bric::Util::Coll::Action internally.

$self = $st->copy
    Sets the copy property to true, meaning that when a job is executed for this server type, all the resources should be copied to a temporary directory before the actions are applied to them.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->no_copy
    Sets the copy property to false, meaning that when a job is executed for this server type, all the resources will have the actions applied to them in place, without first moving them to a temporary directory.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->can_copy
    Returns $self if the resources should be copied to a temporary directory before performing actions on them, and false if the actions can be applied to the resources in place.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->on_publish
    Sets the copy publish to true, meaning that this server type should be used for publish events.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->no_publish
    Sets the publish property to false, meaning that this server type should be used for jobs triggered by publish events.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->can_publish
    Returns $self if this server type is used to move files for a publish event.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->on_preview
    Sets the copy preview to true, meaning that this server type should be used for preview events.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->no_preview
    Sets the preview property to false, meaning that this server type should be used for jobs triggered by preview events.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->can_preview
    Returns $self if this server type is used to move files for a preview event.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->activate
    Activates the Bric::Dist::ServerType object. Call $st->save to make the change persistent. Bric::Dist::ServerType objects instantiated by new() are active by default.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->deactivate
    Deactivates (deletes) the Bric::Dist::ServerType object. Call $st->save to make the change persistent.

    Throws:

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->is_active
    Returns $self if the Bric::Dist::ServerType object is active, and undef if it is not.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $st->save
    Saves any changes to the Bric::Dist::ServerType object. Returns $self on success and undef on failure.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to execute SQL statement.

    •   Unable to select row.

    •   Incorrect number of args to _set.

    •   Bric::_set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

PRIVATE

  Private Class Methods
NONE.

  Private Instance Methods

my $mover_class = $st->_get_mover_class()
    Returns the Class (package) name of the class used to move resources. Used by Bric::Dist::Action::Mover so that it knows who to tell to do the moving.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    Side Effects: If the move method has been changed via set_move_method() since the current object was instantiated, this method will return the old package name rather than the new one. To get the new one, instantiate the object but don't change its method. If you really want to change it, do so, save it, and then re-instantiate it via Bric::Dist::ServerType->lookup().

    Notes: NONE>

  Private Functions

my $st_aref = &$get_em( $pkg, $params )
my $st_ids_aref = &$get_em( $pkg, $params, 1 )
    Function used by "lookup()" and "list()" to return a list of Bric::Dist::ServerType objects or, if called with an optional third argument, returns a list of Bric::Dist::ServerType object IDs (used by "list_ids()").

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes:

my $rules = &$get_coll($self, $class, $key)
    Returns the collection of objects stored under $key in $self. The collection is a subclass Bric::Util::Coll object, identified by $class. See Bric::Util::Coll for interface details.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Unable to prepare SQL statement.

    •   Unable to connect to database.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

NOTES
NONE.

AUTHOR
David Wheeler <david@justatheory.com>

SEE ALSO
Bric