| 1 | 4 | ▶ | use strict; # redundant, but quiets perlcritic |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | package MooX::StrictConstructor::Role::Constructor::Base; | ||
| 4 | |||
| 5 | 4 | our $VERSION = '0.013'; | |
| 6 | |||
| 7 | 4 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 7 | ▶ | sub _check_strict { |
|
Subroutine
_check_strict: called CC=1 SCAR=0.0
| |||
| 10 | 7 | my ($self, $spec, $arg) = @_; | |
| 11 | my $captures = { | ||
| 12 | '%MooX_StrictConstructor_attrs' => { | ||
| 13 | map +($_ => 1), | ||
| 14 | grep defined, | ||
| 15 | map $_->{init_arg}, | ||
| 16 | 7 | values %$spec, | |
| 17 | }, | ||
| 18 | }; | ||
| 19 | 7 | my $code = sprintf(<<'END_CODE', $arg); | |
| 20 | if ( my @bad = grep !exists $MooX_StrictConstructor_attrs{$_}, keys %%{%s} ) { | ||
| 21 | require Carp; | ||
| 22 | Carp::croak( | ||
| 23 | "Found unknown attribute(s) passed to the constructor: " . | ||
| 24 | join(", ", sort @bad) | ||
| 25 | ); | ||
| 26 | } | ||
| 27 | END_CODE | ||
| 28 | 7 | return ($code, $captures); | |
| 29 | } | ||
| 30 | |||
| 31 | 4 | 1; | |
| 32 | |||
| 33 | __END__ | ||