Object::Declare 0.13 review
DownloadObject::Declare is a Perl module for declarative object constructor. SYNOPSIS use Object::Declare ['MyApp::Column', 'MyApp:
|
|
Object::Declare is a Perl module for declarative object constructor.
SYNOPSIS
use Object::Declare ['MyApp::Column', 'MyApp::Param'];
my %objects = declare {
param foo =>
!is global,
is immutable,
valid_values are qw( more values );
column bar =>
field1 is 'value',
field2 is 'some_other_value';
};
print $objects{foo}; # a MyApp::Param object
print $objects{bar}; # a MyApp::Column object
This module exports one function, declare, for building named objects with a declarative syntax, similar to how Jifty::DBI::Schema defines its columns.
In list context, declare returns a list of name/object pairs in the order of declaration (allowing duplicates), suitable for putting into a hash. In scalar context, declare returns a hash reference.
Using a flexible import interface, one can change exported helper functions names (declarator), words to link labels and values together (copula), and the table of named classes to declare (mapping):
use Object::Declare
declarator => ['declare'], # list of declarators
copula => { # list of words, or a map
is => '', # from copula to prefixes for
are => '', # labels built with that copula
}
aliases => { # list of label aliases:
more => 'less', # turns "is more" into "is less"
# and "more is 1" into "less is 1"
},
mapping => {
column => 'MyApp::Column', # class name to call ->new to
param => sub { # arbitrary coderef also works
bless(@_, 'MyApp::Param');
},
};
After the declarator block finishes execution, all helper functions are removed from the package. Same-named functions (such as &is and &are) that existed before the declarator's execution are restored correctly.
Requirements:
Perl
Object::Declare 0.13 keywords