File Coverage

blib/lib/MooX/StrictConstructor/Role/BuildAll.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1 2     2   232129 use strict; # redundant, but quiets perlcritic
  2         6  
  2         122  
2 2     2   13 use warnings;
  2         5  
  2         235  
3             package MooX::StrictConstructor::Role::BuildAll;
4              
5             our $VERSION = '0.013';
6              
7 2     2   589 use Moo::Role;
  2         20141  
  2         15  
8              
9             has _constructor_generator => (
10             is => 'rw',
11             weaken => 1,
12             );
13              
14             around buildall_body_for => sub {
15             my ($orig, $self, $into, $me, $args, @extra) = @_;
16              
17             my $con = $self->_constructor_generator;
18             my $fake_BUILD = $con->can('_fake_BUILD');
19             my $real_build = ! do {
20 2     2   1495 no strict 'refs';
  2         6  
  2         847  
21             defined &{"${into}::BUILD"} && \&{"${into}::BUILD"} == $fake_BUILD;
22             };
23              
24             my $code = '';
25             if ($real_build) {
26             $code .= $self->$orig($into, $me, $args, @extra);
27             }
28             my $arg = $args =~ /^\$\w+(?:\[[0-9]+\])?$/ ? $args : "($args)[0]";
29             $code .= "do {\n" . $con->_cap_call($con->_check_strict($con->all_attribute_specs, $arg)) . "},\n";
30             return $code;
31             };
32              
33             1;
34              
35             __END__