WiX3/Util/Trait/StrictConstructor/Class.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 58 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package # Hide from PAUSE.
2 WiX3::Util::Trait::StrictConstructor::Class;
3  
4 # Corresponds to MooseX::StrictConstructor::Trait::Class
5 # 0.010004 = MX::SC 0.16
6  
7 use 5.008003;
8 use strict;
9 use warnings;
10 use Moose::Role 2;
11 use namespace::autoclean;
12 use WiX3::Exceptions;
13 use B qw();
14  
15 our $VERSION = '0.011';
16  
17 around new_object => sub {
18 my $orig = shift;
19 my $self = shift;
20 my $params = @_ == 1 ? $_[0] : {@_};
21 my $instance = $self->$orig(@_);
22  
23 my %attrs = (
24 __INSTANCE__ => 1,
25 ( map { $_ => 1 }
26 grep {defined}
27 map { $_->init_arg() } $self->get_all_attributes() ) );
28  
29 my @bad = sort grep { !$attrs{$_} } keys %{$params};
30  
31 if (@bad) {
32 WiX3::Exception::Parameter->throw(
33 "Found unknown attribute(s) init_arg passed to the constructor: @bad"
34 );
35 }
36  
37 return $instance;
38 };
39  
40 around '_inline_BUILDALL' => sub {
41 my $orig = shift;
42 my $self = shift;
43  
44 my @source = $self->$orig();
45  
46 my @attrs = (
47 '__INSTANCE__ => 1,',
48 map { B::perlstring($_) . ' => 1,' }
49 grep {defined}
50 map { $_->init_arg() } $self->get_all_attributes() );
51  
52 ##no critic(RequireInterpolationOfMetachars)
53 return (
54 @source,
55 'my %attrs = (' . ( join q{ }, @attrs ) . ');',
56 'my @bad = sort grep { !$attrs{$_} } keys %{ $params };',
57 'if (@bad) {',
58 'WiX3::Exception::Parameter->throw(',
59 '"Found unknown attribute(s) passed to the constructor: @bad");',
60 '}',
61 );
62 };
63  
64 1;