The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Myco::QueryTemplate - a Myco template class

DESCRIPTION

A template class for Myco::Query and Myco::Entity::Meta::Query. Provides full encapsulation of Tangram Query object construction and manipulation.

COMMON ENTITY INTERFACE

Constructor, accessors, and other methods -- as inherited from Myco::Entity.

ATTRIBUTES

Attributes may be initially set during object construction (with new()) but otherwise are accessed solely through accessor methods. Typical usage:

  • Set attribute value

     $obj->set_attribute($value);

    Check functions (see Class::Tangram) perform data validation. If there is any concern that the set method might be called with invalid data then the call should be wrapped in an eval block to catch exceptions that would result.

  • Get attribute value

     $value = $obj->get_attribute;

A listing of available attributes follows:

name

 type: string

Name of the query.

description

 type: string  required

Description of the query.

result_remote

 type: string  required

The remote class of objects to return.

filter

 type: perl_dump

  $query->set_filter( $filter );

The string dump of ::Filter and ::Clause objects comprising the filter.

remotes

 type: flat_hash  required

 $query->set_remote( {'$u_' => 'Myco::User'} );

A hash of remote variable and class names. Use declare_remote to add new ones.

params

 type: perl_dump

  $query->set_params( last_name => ['$p_', 'last'],
                      middle_name => ['$p_', 'middle', 1],
                      first_initial => ['$p_', 'middle',
                                        widget => ['textfield',
                                                   -size => 2, maxlength => 2],
                                       ],
                    );

A hash of arrays of arg names consisting of the relevant remotes, and the attribute name. May also include boolean flag to indicate optionality, as well as a custom CGI widget spec.

params_order

  $query->set_params_order( ['mid', 'log'] );

Since params is a hash, its values cannot be accessed in the order it was originally specified, this attribute can used to explicity set the order.

ADDED CLASS / INSTANCE METHODS

add_remotes

  $query->add_remotes( { '$peeps_' => 'Myco::Person',
                         '$stooges_' => 'Myco::Person::Stooge'} );

Add remotes without clobbering the current list.

get_filter_string

  my $filter_string = $query->get_filter_string;

A wrapper method around Myco::Query::Part::Filter->get_combined_parts. Works on the filter attribute. Accepts as an argument the same hash of parameters passed to run_query.

run_query

  my @results = $query->run_query;

Run the query.

get_ui_md

  my $ui_md = $query->get_ui_md;

Returns ::UI metadata objects for each attribute in params attribute. Keyed by attribute alias

get_ref_params

  my $ref_params = $query->get_ref_params;

Returns a hash reference like { 'person' => 'Myco::Person' } for any 'ref' or 'iset' params required by the query object.

get_closure

  my $cgi_widget = $query->get_closure( 'first_name' );

Get an appropriate CGI widget for a given param. Leverages Myco::Entity::Meta::Attribute::UI.