NAME
App::Dochazka::Common::Model - functions shared by several modules within the data model
SYNOPSIS
Shared data model functions. All three functions are designed to be used together as follows:
package My::Package;
use Params::Validate qw( :all );
BEGIN {
no strict 'refs';
*{"spawn"} = App::Dochazka::Common::Model::make_spawn;
*{"reset"} = App::Dochazka::Common::Model::make_reset(
'attr1', 'attr2',
);
*{"attr1"} = App::Dochazka::Common::Model::make_accessor( 'attr1' );
*{"attr2"} = App::Dochazka::Common::Model::make_accessor( 'attr2', { type => HASHREF } );
}
What this does:
create a
spawn
class method in your classcreate a
reset
instance method in your classcreate a
attr1
accessor method in your class (type defaults to SCALAR)create a
attr2
accessor method in your class (type HASHREF)
PACKAGE VARIABLES
Dispatch table used in 'boilerplate'.
FUNCTIONS
boilerplate
Run all the necessary commands to "install" the methods inside your module. Call like this:
use App::Dochazka::Common::Model;
use constant ATTRS => qw( ... );
BEGIN {
App::Dochazka::Common::Model::boilerplate( __PACKAGE__, ATTRS );
}
where the constant ATTRS contains the list of object properties.
This routine requires some explanation. It's purpose is to generate "boilerplate" code for the modules under App::Dochazka::Common::Model
. That includes the following methods:
spawn
filter
reset
TO_JSON
compare
compare_disabled
clone
attrs
get
set
as well as basic accessors for that model/class.
The boilerplate
routine takes a module name and a list of attributes (object property names), and returns nothing.
make_spawn
Returns a ready-made 'spawn' method for your class/package/module.
make_filter
Given a list of attributes, returns a ready-made 'filter' routine which takes a PROPLIST and returns a new PROPLIST from which all bogus properties have been removed.
make_reset
Given a list of attributes, returns a ready-made 'reset' method.
make_accessor
Returns a ready-made accessor.
make_TO_JSON
Returns a ready-made TO_JSON
make_compare
Returns a ready-made 'compare' method that can be used to determine if two objects are the same.
make_compare_disabled
Returns a ready-made 'compare' method that can be used to determine if two objects are the same. For use with objects containing a 'disabled' property where 'undef' and 'false' are treatd as functionally the same.
make_clone
Returns a ready-made 'clone' method.
make_attrs
Returns a ready-made 'attrs' method.
make_get
Returns a ready-made 'get' method.
make_set
Returns a ready-made 'set' method, which takes the name of an attribute and a value to set that attribute to. Returns true value on success, false on failure.
AUTHOR
Nathan Cutler, <presnypreklad@gmail.com>