Name

Bric::Dist::Server - Interface for managing servers to which content will be distributed.

Synopsis

use Bric::Dist::Server;

# Constructors.
# Create a new object.
my $server = Bric::Dist::Server->new;
# Look up an existing object.
$server = Bric::Dist::Server->lookup({ id => 1 });
# Get a list of server objects.
my @servers = Bric::Dist::Server->list({ server_type_id => 2 });
# Get an anonymous hash of server objects.
my $servers_href = Bric::Dist::Server->href({ home_path => '/home/www' });

# Class methods.
# Get a list of object IDs.
my @server_ids = Bric::Dist::Server->list_ids({ server_type_id => 2 });
# Get an introspection hashref.
my $int = Bric::Dist::Server->my_meths;

# Instance Methods.
my $id = $server->get_id;
my $server_type_id = $server->get_server_type_id;
$server = $server->set_server_type_id($server_type_id);
my $host_name = $server->get_host_name;
$server = $server->set_host_name($host_name);
my $doc_root = $server->get_doc_root;
$server = $server->set_doc_root($doc_root);
my $login = $server->get_login;
$server = $server->set_login($login);
my $password = $server->get_password;
$server = $server->set_password($password);
my $cookie = $server->get_cookie;
$server = $server->set_cookie($cookie);

# Save it.
$server->save;

# Delete it.
$server->del;
$server->save;

Description

This class manages server objects. Servers are individual instances of a type defined by Bric::Dist::ServerType. They are provide accessors to values that are unique to each server, such as host name, login, password, cookie, etc. Thus, when a job is scheduled to move files to the servers of a given server type, they can be successfully moved using the unique properties of each server.

Interface

Constructors

my $server = Bric::Dist::Server->new($init)

Instantiates a Bric::Dist::Server 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 $server->save() to save the new object.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $server = Bric::Dist::Server->lookup({ id => $id })

Looks up and instantiates a new Bric::Dist::Server object based on the Bric::Dist::Server 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::Server object with data from the database before returning it.

Notes: NONE.

my (@servers || $servers_aref) = Bric::Dist::Server->list($params)

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

id

Server ID. May use ANY for a list of possible values.

host_name

The server host name. May use ANY for a list of possible values.

os

The server operating system. May use ANY for a list of possible values.

doc_root

The document root to distribute to. May use ANY for a list of possible values.

login

The login username for the server. May use ANY for a list of possible values.

password

The login password for the server. May use ANY for a list of possible values.

cookie

The cookie to use to connect to the server. May use ANY for a list of possible values.

server_type_id

The destination (Bric::Dist::ServerType) ID with which a server may be associated. May use ANY for a list of possible values.

active

Boolean value indicating whether the server object is active.

Throws:

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

Notes: NONE.

my $servers_href = Bric::Dist::Server->href($params)

Returns an anonymous hash of Bric::Dist::Server 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::Server object with data from the database before returning them all.

Notes: NONE.

Destructors

$server->DESTROY

Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Public Class Methods

my (@server_ids || $server_ids_aref) = Bric::Dist::Server->list_ids($params)

Returns a list or anonymous array of Bric::Dist::Server 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.

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

my (@oses || $oses_aref) = Bric::Dist::Server->list_oses

Returns a list of supported server operating systems.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Public Instance Methods

my $id = $server->get_id

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

Throws:

Side Effects: NONE.

Notes: If the Bric::Dist::Server 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 $server_type_id = $server->get_server_type_id

Returns the ID of the Bric::Dist::ServerType object with which this server is associated.

Throws:

Side Effects: NONE.

Notes: NONE.

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

Sets the ID of the Bric::Dist::ServerType object with which this server is associated.

Throws:

Side Effects: NONE.

Notes: NONE.

my $host_name = $server->get_host_name
my $host_name = $server->get_name

Returns the server's host name.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->set_host_name($host_name)

Sets the server's host name. The host name will be converted to lower case.

Throws:

Side Effects: NONE.

Notes: NONE.

my $os = $server->get_os

Returns the server's operating system.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->set_os($os)

Sets the server's operating system. Retreive a list of supported OSes from list_oses().

Throws:

Side Effects: NONE.

Notes: NONE.

my $doc_root = $server->get_doc_root

Returns the server's home path. This is the path that will serve as the root directory for all PUTs to the server.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->set_doc_root($doc_root)

Sets the server's home path. This is the path that will serve as the root directory for all PUTs to the server.

Throws:

Side Effects: NONE.

Notes: In the future, we may want to add platform-independent methods of handling paths.

my $login = $server->get_login

Returns the server's login name, which will be used with the password property to interact with the server via FTP and other protocols that require a login and password.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->set_login($login)

Sets the server's login name, which will be used with the password property to interact with the server via FTP and other protocols that require a login and password.

Throws:

Side Effects: NONE.

Notes: NONE.

my $password = $server->get_password

Returns the server's password, which will be used with the login to interact with the server via FTP and other protocols that require a login and password.

Throws:

Side Effects: NONE.

Notes: The password is stored in clear text in the database.

$self = $server->set_password($password)

Sets the server's password, which will be used with the login to interact with the server via FTP and other protocols that require a login and password.

Throws:

Side Effects: NONE.

Notes: The password is stored in clear text in the database.

my $cookie = $server->get_cookie

Returns the cookie that can be used by transfer protocols that require a cookie for authentication, such as WebDAV.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->set_cookie($cookie)

Sets the cookie that can be used by transfer protocols that require a cookie for authentication, such as WebDAV. Converts non-Unix line endings.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$server = $server->del

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

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->activate

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

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->deactivate

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

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->is_active

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

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $server->save

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

Throws:

Side Effects: NONE.

Notes: NONE.

Private

Private Class Methods

NONE.

Private Instance Methods

NONE.

Private Functions

my $server_aref = &$get_em( $pkg, $params )
my $server_ids_aref = &$get_em( $pkg, $params, 1 )
my $server_ids_href = &$get_em( $pkg, $params, 0, 1 )

Function used by lookup() and list() to return a list of Bric::Dist::Server objects or, if called with an optional third argument, returns a listof Bric::Dist::Server object IDs (used by list_ids()). If called with an optional fourth argument, returns an anonymous hash where the keys are the object IDs and the values are the objects themselves.

Throws:

Side Effects: NONE.

Notes: NONE.

Notes

NONE.

Author

David Wheeler <david@justatheory.com>

See Also

Bric, Bric::Dist::ServerType