Venus::Role::Buildable
Buildable Role
Buildable Role for Perl 5
method: build_arg method: build_args method: build_self method: build_nil
package Example;
use Venus::Class;
with 'Venus::Role::Buildable';
attr 'test';
package main;
my $example = Example->new;
# $example->test;
This package modifies the consuming package and provides methods for hooking into object construction of the consuming class, e.g. handling single-arg object construction.
The build_arg method, if defined, is only called during object construction when a single non-hashref is provided.
build_arg(Any $data) (HashRef)
{ since => '0.01', }
=example-1 build_arg
package Example1;
use Venus::Class;
attr 'x';
attr 'y';
with 'Venus::Role::Buildable';
sub build_arg {
my ($self, $data) = @_;
$data = { x => $data, y => $data };
return $data;
}
package main;
my $example = Example1->new(10);
# $example->x;
# $example->y;
The build_args method, if defined, is only called during object construction to hook into the handling of the arguments provided.
build_args(HashRef $data) (HashRef)
{ since => '0.01', }
=example-1 build_args
package Example2;
use Venus::Class;
attr 'x';
attr 'y';
with 'Venus::Role::Buildable';
sub build_args {
my ($self, $data) = @_;
$data->{x} ||= int($data->{x} || 100);
$data->{y} ||= int($data->{y} || 100);
return $data;
}
package main;
my $example = Example2->new(x => 10, y => 10);
# $example->x;
# $example->y;
The build_self method, if defined, is only called during object construction after all arguments have been handled and set.
build_self(HashRef $data) (Self)
{ since => '0.01', }
=example-1 build_self
package Example3;
use Venus::Class;
attr 'x';
attr 'y';
with 'Venus::Role::Buildable';
sub build_self {
my ($self, $data) = @_;
die if !$self->x;
die if !$self->y;
return $self;
}
package main;
my $example = Example3->new(x => 10, y => 10);
# $example->x;
# $example->y;
The build_nil method, if defined, is only called during object construction when a single empty hashref is provided.
build_nil(HashRef $data) (Any)
{ since => '0.01', }
=example-1 build_nil
package Example4;
use Venus::Class;
attr 'x';
attr 'y';
with 'Venus::Role::Buildable';
sub build_nil {
my ($self, $data) = @_;
$data = { x => 10, y => 10 };
return $data;
}
package main;
my $example = Example4->new({});
# $example->x;
# $example->y;
t/Venus.t: pdml: authors t/Venus.t: pdml: license
19 POD Errors
The following errors were encountered while parsing the POD:
- Around line 13:
Unknown directive: =name
- Around line 21:
Unknown directive: =tagline
- Around line 29:
Unknown directive: =abstract
- Around line 37:
Unknown directive: =includes
- Around line 48:
Unknown directive: =synopsis
- Around line 75:
Unknown directive: =description
- Around line 85:
Unknown directive: =method
- Around line 91:
Unknown directive: =signature
- Around line 95:
Unknown directive: =metadata
- Around line 140:
Unknown directive: =method
- Around line 145:
Unknown directive: =signature
- Around line 149:
Unknown directive: =metadata
- Around line 195:
Unknown directive: =method
- Around line 200:
Unknown directive: =signature
- Around line 204:
Unknown directive: =metadata
- Around line 250:
Unknown directive: =method
- Around line 255:
Unknown directive: =signature
- Around line 259:
Unknown directive: =metadata
- Around line 304:
Unknown directive: =partials