Bric::Util::MediaType(3)

NAME
Bric::Util::MediaType - Interface to Media Types.

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2006-03-17 16:26:34 -0800 (Fri, 17 Mar 2006) $

SYNOPSIS
  use Bric::Util::MediaType;

DESCRIPTION
This class may be used for managing media types (a.k.a. "MIME types"). Bricolage ships with a number of default media types accessible via this class. This class may also be used to create new media types.

INTERFACE

  Constructors

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

    *   name

    *   description

    *   ext - An anonymous array of extensions.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

my $mt = Bric::Util::MediaType->lookup({ id => $id })
my $mt = Bric::Util::MediaType->lookup({ name => $name })
my $mt = Bric::Util::MediaType->lookup({ ext => $ext })
    Looks up and instantiates a new Bric::Util::MediaType object based on the Bric::Util::MediaType object ID, name, or filename extension passed. If $id, $name, or $ext is not found in the database, lookup() returns undef.

    Throws:

    *   Too many Bric::Dist::Util::MediaType objects found.

    *   Unable to connect to database.

    *   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.

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

    Notes: NONE.

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

    id  A media type ID. May use "ANY" for a list of possible values.

    name
        A media type name. May use "ANY" for a list of possible values.

    description
        A media type description. May use "ANY" for a list of possible values.

    ext A media type file name extension. May use "ANY" for a list of possible values.

    grp_id
        The ID for a Bric::Util::Grp object of which media types may be members. May use "ANY" for a list of possible values.

    Throws:

    *   Unable to connect to database.

    *   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.

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

    Notes: NONE.

  Destructors

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

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Class Methods

my (@foo_ids || $mt_ids_aref) = Bric::Util::MediaType->list_ids($params)
    Returns a list or anonymous array of Bric::Util::MediaType 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 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.

    Side Effects: NONE.

    Notes: NONE.

my $name = Bric::Util::MediaType->get_name_by_ext($filename)
my $name = Bric::Util::MediaType->get_name_by_ext($ext)
    Returns the name of a media type that is associated with the extension found at the end of $filename. If there is no extension, the entire argument is assumed to be the extension. If the extension doesn't exist in the database, get_name_by_ext() will return undef.

    Throws:

    *   Unable to instantiate cache.

    *   Unable to fetch value from the cache.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to select row.

    *   Unable to cache value.

    Side Effects: NONE.

    Notes: NONE.

my $id = Bric::Util::MediaType->get_id_by_ext($filename)
my $id = Bric::Util::MediaType->get_id_by_ext($ext)
    Returns the id of a Bric::Util::MediaType object that is associated with the extension found at the end of $filename. If there is no extension, the entire argument is assumed to be the extension. If the extension doesn't exist in the database, get_name_by_ext() will return undef.

    Throws:

    *   Unable to instantiate cache.

    *   Unable to fetch value from the cache.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to select row.

    *   Unable to cache value.

    Side Effects: NONE.

    Notes: NONE.

$meths = Bric::Util::MediaType->my_meths
(@meths || $meths_aref) = Bric::Util::MediaType->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Util::MediaType->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 = $mt->get_id
    Returns the ID of the Bric::Util::MediaType 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::Util::MediaType 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 = $mt->get_name
    Returns the media type name, e.g., 'text/html'.

    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 = $mt->set_name($name)
    Sets the media type name.

    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 = $mt->get_description
    Returns the media 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 = $mt->set_description($description)
    Sets the media 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 (@exts || $exts_aref) = $mt->get_exts()
    Returns a list or anonymous array of filename extensions that indicate this media type.

    Throws:

    *   Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $mt->add_exts(@exts)
    Associates extensions with this media type. Note that all extensions must be unique; no two media types can share the same extension.

    Throws:

    *   Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $mt->del_exts(@exts)
    Dissociates extensions from this media type.

    Throws:

    *   Problems retrieving fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $mt->activate
    Activates the Bric::Util::MediaType object. Call $mt->save to make the change persistent. Bric::Util::MediaType 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 = $mt->deactivate
    Deactivates (deletes) the Bric::Util::MediaType object. Call $mt->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 = $mt->is_active
    Returns $self if the Bric::Util::MediaType object is active, and undef if it is not.

    Throws:

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

    Side Effects: NONE.

    Notes: NONE.

$self = $mt->save
    Saves any changes to the Bric::Util::MediaType 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.

    *   Unable to instantiate cache.

    *   Unable to fetch value from the cache.

    *   Unable to cache value.

    Side Effects: NONE.

    Notes: NONE.

PRIVATE

  Private Class Methods
NONE.

  Private Instance Methods
NONE.

  Private Functions

my $mt_aref = &$get_em( $pkg, $params )
my $mt_ids_aref = &$get_em( $pkg, $params, 1 )
    Function used by lookup() and list() to return a list of Bric::Util::MediaType objects or, if called with an optional third argument, returns a listof Bric::Util::MediaType object IDs (used by list_ids()).

    Throws:

    *   Unable to connect to database.

    *   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.

    Side Effects: NONE.

    Notes: NONE.

my $ext_data_aref = &$get_ext_data()
    Looks up the name and id of a media type corresponding to a given filename extension. Returns them in an anonymous array with the ID first and the name second. Used by &$lookup_ext().

    Throws:

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to select row.

    Side Effects: NONE.

    Notes: NONE.

my $id = &$lookup_ext($filename)
my $name = &$lookup_ext($filename, 1)
    Looks up the name or id of a media type corresponding to a given filename extension.

    Throws:

    *   Unable to instantiate cache.

    *   Unable to fetch value from the cache.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to select row.

    *   Unable to cache value.

    Side Effects: NONE.

    Notes: Uses Bric::App::Cache for persistence across processes.

NOTES
NONE.

AUTHOR
David Wheeler <david@justatheory.com>

SEE ALSO
Bric, Bric::Dist::Resource