1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
use strict;
use Test::More tests => 3, import => ['is_deeply'];
use ok 'Object::Declare' =>
copula => {
is => '',
are => 'plural_',
},
aliases => {
field2 => 'fun',
},
mapping => {
column => 'MyApp::Column',
alt_col => sub { return { alt => column(), @_ } }
};
sub column { 1 }
sub MyApp::Column::new { shift; return { @_ } }
sub do_declare { declare {
column x =>
is rw,
is Very::Happy,
field1 is 'xxx',
field2 are 'XXX', 'XXX',
is field3,
parts are column( is happy ), column( !is happy );
alt_col y =>
!is Very::Happy,
field1 is 'yyy',
field2 is 'YYY',
col is column( is happy );
} }
my @objects = do_declare;
is_deeply(\@objects => [
x => {
'name' => 'x',
'field1' => 'xxx',
'plural_field2' => ['XXX', 'XXX'],
'plural_parts' =>[ { happy => 1 },{ happy => '' },],
'field3' => 1,
'rw' => 1,
'Very::Happy' => 1,
},
y => {
'name' => 'y',
'field1' => 'yyy',
'fun' => 'YYY',
'alt' => 1,
col => {
'name' => 'col',
'happy' => 1,
},
'Very::Happy' => '',
},
], 'object declared correctly (list context)');
my $objects = do_declare;
is_deeply($objects => {
x => {
'name' => 'x',
'field1' => 'xxx',
'plural_field2' => ['XXX', 'XXX'],
'plural_parts' =>[ {happy => 1},{happy => ''},],
'field3' => 1,
'rw' => 1,
'Very::Happy' => 1,
},
y => {
'name' => 'y',
'field1' => 'yyy',
'fun' => 'YYY',
'alt' => 1,
col => {
'name' => 'col',
'happy' => 1,
},
'Very::Happy' => '',
},
}, 'object declared correctly (scalar context)');
|