App::Dochazka::Common::Model - functions shared by several modules within the data model
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 class
spawn
create a reset instance method in your class
reset
create a attr1 accessor method in your class (type defaults to SCALAR)
attr1
create a attr2 accessor method in your class (type HASHREF)
attr2
Dispatch table used in '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:
App::Dochazka::Common::Model
filter
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.
boilerplate
Returns a ready-made 'spawn' method for your class/package/module.
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.
Given a list of attributes, returns a ready-made 'reset' method.
Returns a ready-made accessor.
Returns a ready-made TO_JSON
Returns a ready-made 'compare' method that can be used to determine if two objects are the same.
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.
Returns a ready-made 'clone' method.
Returns a ready-made 'attrs' method.
Returns a ready-made 'get' method.
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.
Nathan Cutler, <presnypreklad@gmail.com>
<presnypreklad@gmail.com>
To install App::Dochazka::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Dochazka::Common
CPAN shell
perl -MCPAN -e shell install App::Dochazka::Common
For more information on module installation, please visit the detailed CPAN module installation guide.