Data-Object-Role-Formulatable
view release on metacpan or search on metacpan
"perl" : "5.014",
"routines" : "0",
"strict" : "0",
"warnings" : "0"
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/iamalnewkirk/data-object-role-formulatable/issues"
},
"homepage" : "https://metacpan.org/release/Data-Object-Role-Formulatable",
"repository" : {
"type" : "git",
"url" : "git://github.com/iamalnewkirk/data-object-role-formulatable.git",
"web" : "https://github.com/iamalnewkirk/data-object-role-formulatable"
}
},
"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"
}
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:
bugtracker: https://github.com/iamalnewkirk/data-object-role-formulatable/issues
homepage: https://metacpan.org/release/Data-Object-Role-Formulatable
repository: git://github.com/iamalnewkirk/data-object-role-formulatable.git
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
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'
}
}
package main;
my $student = Test::Student->new({
name => 'levi nolan',
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']
});
# $teacher->name;
# <Test::Data::Str>
# $teacher->dates;
# [<Test::Data::Str>]
This package supports automatically calling "before" and "after"
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"
<https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/LICENSE>.
PROJECT
Wiki
<https://github.com/iamalnewkirk/data-object-role-formulatable/wiki>
Project <https://github.com/iamalnewkirk/data-object-role-formulatable>
Initiatives
<https://github.com/iamalnewkirk/data-object-role-formulatable/projects>
Milestones
<https://github.com/iamalnewkirk/data-object-role-formulatable/milestones>
Contributing
<https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/CONTRIBUTE.md>
Issues
<https://github.com/iamalnewkirk/data-object-role-formulatable/issues>
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'
}
}
package main;
my $student = Test::Student->new({
name => 'levi nolan',
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']
});
# $teacher->name;
# <Test::Data::Str>
# $teacher->dates;
# [<Test::Data::Str>]
This package supports automatically calling _"before"_ and _"after"_ 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"](https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/LICENSE).
# PROJECT
[Wiki](https://github.com/iamalnewkirk/data-object-role-formulatable/wiki)
[Project](https://github.com/iamalnewkirk/data-object-role-formulatable)
[Initiatives](https://github.com/iamalnewkirk/data-object-role-formulatable/projects)
[Milestones](https://github.com/iamalnewkirk/data-object-role-formulatable/milestones)
[Contributing](https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/CONTRIBUTE.md)
[Issues](https://github.com/iamalnewkirk/data-object-role-formulatable/issues)
lib/Data/Object/Role/Formulatable.pm view on Meta::CPAN
use routines;
use Data::Object::Role;
use Data::Object::RoleHas;
use Data::Object::Space;
use Scalar::Util ();
with 'Data::Object::Role::Buildable';
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
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'
}
}
package main;
my $student = Test::Student->new({
name => 'levi nolan',
lib/Data/Object/Role/Formulatable.pm view on Meta::CPAN
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']
});
# $teacher->name;
# <Test::Data::Str>
# $teacher->dates;
# [<Test::Data::Str>]
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.
=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
file"|https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/LICENSE>.
=head1 PROJECT
L<Wiki|https://github.com/iamalnewkirk/data-object-role-formulatable/wiki>
L<Project|https://github.com/iamalnewkirk/data-object-role-formulatable>
L<Initiatives|https://github.com/iamalnewkirk/data-object-role-formulatable/projects>
L<Milestones|https://github.com/iamalnewkirk/data-object-role-formulatable/milestones>
L<Contributing|https://github.com/iamalnewkirk/data-object-role-formulatable/blob/master/CONTRIBUTE.md>
L<Issues|https://github.com/iamalnewkirk/data-object-role-formulatable/issues>
=cut
t/Data_Object_Role_Formulatable.t view on Meta::CPAN
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'
}
}
package main;
my $student = Test::Student->new({
name => 'levi nolan',
t/Data_Object_Role_Formulatable.t view on Meta::CPAN
This package provides a mechanism for automatically inflating objects from
constructor 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
package 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.873 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )