File Coverage

blib/lib/MooX/StrictConstructor/Role/Constructor/Late.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 5 80.0
pod n/a
total 16 17 94.1


line stmt bran cond sub pod time code
1 2     2   222078 use strict; # redundant, but quiets perlcritic
  2         5  
  2         85  
2 2     2   13 use warnings;
  2         4  
  2         236  
3             package MooX::StrictConstructor::Role::Constructor::Late;
4              
5             our $VERSION = '0.013';
6              
7 2     2   547 use Moo::Role;
  2         18943  
  2         15  
8              
9             with 'MooX::StrictConstructor::Role::Constructor::Base';
10              
11             has _buildall_generator => ( is => 'rw' );
12              
13             around buildall_generator => sub {
14             my ($orig, $self, @args) = @_;
15             my $gen = $self->_buildall_generator;
16             return $gen
17             if $gen;
18             $gen = Moo::Role->apply_roles_to_object($self->$orig(@args),
19             'MooX::StrictConstructor::Role::BuildAll'
20             );
21             $gen->_constructor_generator($self);
22             return $self->_buildall_generator($gen);
23             };
24              
25       0     sub _fake_BUILD {}
26              
27             around generate_method => sub {
28             my ($orig, $self, $into, @args) = @_;
29 2     2   1539 no strict 'refs';
  2         6  
  2         260  
30             # this ensures BuildAll generation will always be done, but allows us to
31             # identify when the BUILD calls aren't needed.
32             local *{"${into}::BUILD"} = \&_fake_BUILD
33             if !$into->can('BUILD');
34             $self->$orig($into, @args);
35             };
36              
37             1;
38              
39             __END__