Data-Object-Role-Formulatable
view release on metacpan or search on metacpan
45464748495051525354555657585960616263646566676869
"perl"
:
"5.014"
,
"routines"
:
"0"
,
"strict"
:
"0"
,
"warnings"
:
"0"
}
}
},
"release_status"
:
"stable"
,
"resources"
: {
"bugtracker"
: {
},
"repository"
: {
"type"
:
"git"
,
}
},
"version"
:
"0.03"
,
"x_authority"
:
"cpan:AWNCORP"
,
"x_generated_by_perl"
:
"v5.26.1"
,
"x_serialization_backend"
:
"Cpanel::JSON::XS version 4.19"
,
"x_spdx_expression"
:
"Apache-2.0"
}
282930313233343536373839404142434445
Data::Object::ClassHas:
'2.01'
Data::Object::Role:
'2.01'
Data::Object::Role::Buildable:
'0.03'
Data::Object::RoleHas:
'2.01'
Data::Object::Space:
'2.01'
perl:
'5.014'
routines:
'0'
strict:
'0'
warnings:
'0'
resources:
version:
'0.03'
x_authority: cpan:AWNCORP
x_generated_by_perl: v5.26.1
x_serialization_backend:
'YAML::Tiny version 1.73'
x_spdx_expression: Apache-2.0
141516171819202122232425262728293031323334use
routines;
use
Data::Object::Class;
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
package
main;
my
$student
= Test::Student->new({
name
=>
'levi nolan'
,
707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
sub
after_formulate {
{
name
=> 1
}
}
sub
after_formulate_name {
my
(
$self
,
$value
) =
@_
;
$value
}
sub
before_formulate {
{
name
=> 1
}
}
sub
before_formulate_name {
my
(
$self
,
$value
) =
@_
;
$value
}
my
$teacher
= Test::Teacher->new({
name
=>
'levi nolan'
,
dates
=> [
'1587717124'
,
'1587717169'
]
});
# $teacher->name;
# <Test::Data::Str>
# $teacher->dates;
# [<Test::Data::Str>]
routines specific to
each
piece of data provided. This is automatically
enabled
if
the presence of a before_formulate and/or after_formulate
routine is detected. If so, these routines should
return
a hashref
keyed off the class attributes where the
values
are either 1 (denoting
that the hook name should be generated) or some other routine name.
AUTHOR
Al Newkirk, awncorp
@cpan
.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under
the terms of the The Apache License, Version 2.0, as elucidated in the
"license file"
PROJECT
Wiki
Initiatives
Milestones
Contributing
Issues
141516171819202122232425262728293031323334use
routines;
use
Data::Object::Class;
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
package
main;
my
$student
= Test::Student->new({
name
=>
'levi nolan'
,
707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
sub
after_formulate {
{
name
=> 1
}
}
sub
after_formulate_name {
my
(
$self
,
$value
) =
@_
;
$value
}
sub
before_formulate {
{
name
=> 1
}
}
sub
before_formulate_name {
my
(
$self
,
$value
) =
@_
;
$value
}
my
$teacher
= Test::Teacher->new({
name
=>
'levi nolan'
,
dates
=> [
'1587717124'
,
'1587717169'
]
});
# $teacher->name;
# <Test::Data::Str>
# $teacher->dates;
# [<Test::Data::Str>]
specific to
each
piece of data provided. This is automatically enabled
if
the
presence of a `before_formulate` and/or `after_formulate` routine is
detected. If so, these routines should
return
a hashref keyed off the class
attributes where the
values
are either `1` (denoting that the hook name should
be generated) or some other routine name.
# AUTHOR
Al Newkirk, `awncorp
@cpan
.org`
# LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms
of the The Apache License, Version 2.0, as elucidated in the ["license
# PROJECT
[Contributing](https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/CONTRIBUTE.md)
lib/Data/Object/Role/Formulatable.pm view on Meta::CPAN
9101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108use
routines;
use
Data::Object::Role;
use
Data::Object::Space;
use
Scalar::Util ();
requires
'formulate'
;
our
$VERSION
=
'0.03'
;
# VERSION
around
BUILDARGS(
@args
) {
my
$results
;
$results
=
$self
->formulate(
$self
->
$orig
(
@args
));
return
$results
;
}
around
formulate(
$args
) {
my
$results
;
my
$form
=
$self
->
$orig
(
$args
);
# before
if
(
$self
->can(
'before_formulate'
)) {
my
$config
=
$self
->before_formulate(
$args
);
for
my
$key
(
keys
%$config
) {
next
unless
$form
->{
$key
};
next
unless
exists
$args
->{
$key
};
my
$name
=
$config
->{
$key
} eq
'1'
?
"before_formulate_${key}"
:
$config
->{
$key
};
next
unless
$self
->can(
$name
);
$args
->{
$key
} =
$self
->
$name
(
$args
->{
$key
});
}
}
# formulation
$results
=
$self
->formulation(
$args
,
$form
);
# after
if
(
$self
->can(
'after_formulate'
)) {
my
$config
=
$self
->after_formulate(
$results
);
for
my
$key
(
keys
%$config
) {
next
unless
$form
->{
$key
};
next
unless
exists
$results
->{
$key
};
my
$name
=
$config
->{
$key
} eq
'1'
?
"after_formulate_${key}"
:
$config
->{
$key
};
next
unless
$self
->can(
$name
);
$results
->{
$key
} =
$self
->
$name
(
$results
->{
$key
});
}
}
return
$results
;
}
method formulate_object(Str
$name
, Any
$value
) {
my
$results
;
my
$package
= Data::Object::Space->new(
$name
)->load;
if
(Scalar::Util::blessed(
$value
) &&
$value
->isa(
$package
)) {
$results
=
$value
;
}
elsif
(
ref
$value
eq
'ARRAY'
) {
$results
= [
map
$package
->new(
$_
),
@$value
];
}
else
{
$results
=
$package
->new(
$value
);
}
return
$results
;
}
method formulation(HashRef
$args
, HashRef[Str]
$form
) {
my
$results
= {};
for
my
$name
(
grep
{
exists
$args
->{
$_
}}
sort
keys
%$form
) {
$results
->{
$name
} =
$self
->formulate_object(
$form
->{
$name
},
$args
->{
$name
});
}
return
$results
;
}
1;
=encoding utf8
=head1 NAME
lib/Data/Object/Role/Formulatable.pm view on Meta::CPAN
125126127128129130131132133134135136137138139140141142143144145use
routines;
use
Data::Object::Class;
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
package
main;
my
$student
= Test::Student->new({
name
=>
'levi nolan'
,
lib/Data/Object/Role/Formulatable.pm view on Meta::CPAN
191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
sub
after_formulate {
{
name
=> 1
}
}
sub
after_formulate_name {
my
(
$self
,
$value
) =
@_
;
$value
}
sub
before_formulate {
{
name
=> 1
}
}
sub
before_formulate_name {
my
(
$self
,
$value
) =
@_
;
$value
}
my
$teacher
= Test::Teacher->new({
name
=>
'levi nolan'
,
dates
=> [
'1587717124'
,
'1587717169'
]
});
# $teacher->name;
# <Test::Data::Str>
# $teacher->dates;
# [<Test::Data::Str>]
specific to
each
piece of data provided. This is automatically enabled
if
the
presence of a C<before_formulate> and/or C<after_formulate> routine is
detected. If so, these routines should
return
a hashref keyed off the class
attributes where the
values
are either C<1> (denoting that the hook name should
be generated) or some other routine name.
=cut
=head1 AUTHOR
Al Newkirk, C<awncorp@cpan.org>
=head1 LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms
of the The Apache License, Version 2.0, as elucidated in the L<"license
=head1 PROJECT
L<Contributing|https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/CONTRIBUTE.md>
=cut
t/Data_Object_Role_Formulatable.t view on Meta::CPAN
353637383940414243444546474849505152535455use
routines;
use
Data::Object::Class;
has
'name'
;
has
'dates'
;
sub
formulate {
{
name
=>
'test/data/str'
,
dates
=>
'test/data/str'
}
}
package
main;
my
$student
= Test::Student->new({
name
=>
'levi nolan'
,
t/Data_Object_Role_Formulatable.t view on Meta::CPAN
8081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145constructor arguments.
=cut
=scenario automation
This package supports automatically calling I<"before"> and I<"after"> routines
specific to each piece of data provided. This is automatically enabled if the
presence of a C<before_formulate> and/or C<after_formulate> routine is
detected. If so, these routines should return a hashref keyed off the class
attributes where the values are either C<1> (denoting that the hook name should
be generated) or some other routine name.
=example automation
package Test::Teacher;
use registry;
use routines;
use Data::Object::Class;
use Data::Object::ClassHas;
with 'Data::Object::Role::Formulatable';
has 'name';
has 'dates';
sub formulate {
{
name => 'test/data/str',
dates => 'test/data/str'
}
}
sub after_formulate {
{
name => 1
}
}
sub after_formulate_name {
my ($self, $value) = @_;
$value
}
sub before_formulate {
{
name => 1
}
}
sub before_formulate_name {
my ($self, $value) = @_;
$value
}
package main;
my $teacher = Test::Teacher->new({
name => 'levi nolan',
dates => ['1587717124', '1587717169']
t/Data_Object_Role_Formulatable.t view on Meta::CPAN
156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196package
main;
my
$test
= testauto(__FILE__);
my
$subs
=
$test
->standard;
$subs
->synopsis(fun(
$tryable
) {
ok
my
$result
=
$tryable
->result;
ok
$result
->isa(
'Test::Student'
);
ok
$result
->does(
'Data::Object::Role::Formulatable'
);
ok
$result
->can(
'formulate'
);
ok
$result
->can(
'formulate_object'
);
ok
$result
->can(
'formulation'
);
is
ref
$result
->dates,
'ARRAY'
;
ok
$result
->name;
ok
$result
->name->isa(
'Test::Data::Str'
);
ok
$result
->dates->[0]->isa(
'Test::Data::Str'
);
ok
$result
->dates->[1]->isa(
'Test::Data::Str'
);
$result
});
$subs
->scenario(
'automation'
, fun(
$tryable
) {
ok
my
$result
=
$tryable
->result;
ok
$result
->isa(
'Test::Teacher'
);
ok
$result
->does(
'Data::Object::Role::Formulatable'
);
ok
$result
->can(
'formulate'
);
ok
$result
->can(
'formulate_object'
);
ok
$result
->can(
'formulation'
);
is
ref
$result
->dates,
'ARRAY'
;
ok
$result
->name;
ok
$result
->name->isa(
'Test::Data::Str'
);
ok
$result
->dates->[0]->isa(
'Test::Data::Str'
);
ok
$result
->dates->[1]->isa(
'Test::Data::Str'
);
$result
});
( run in 0.606 second using v1.01-cache-2.11-cpan-0d8aa00de5b )