| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package MooX::StrictConstructor; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | our $VERSION = '0.013'; | |||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use Moo (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Moo::Role (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Moo::_Utils qw(_install_modifier); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 6 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=4 SCAR=14.5
| |||||||||||
| 13 | 6 | my $class = shift; | |||||||||
| 14 | 6 | my $target = caller; | |||||||||
| 15 | 6 | my $late; | |||||||||
| 16 | 6 | for my $arg (@_) { | |||||||||
| 17 | 1 | ▶ | if ($arg eq '-late') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 1 | $late = 1; | |||||||||
| 19 | } | ||||||||||
| 20 | else { | ||||||||||
| 21 | 0 | Carp::croak("Unknown option $arg"); | |||||||||
| 22 | } | ||||||||||
| 23 | } | ||||||||||
| 24 | 6 | ▶ | unless ( Moo->is_class($target) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | Carp::croak("MooX::StrictConstructor can only be used on Moo classes."); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 6 | _apply_role($target, $late); | |||||||||
| 29 | |||||||||||
| 30 | 2 | ▶ | _install_modifier($target, 'after', 'extends', sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | _apply_role($target, $late); | |||||||||
| 32 | 6 | }); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 8 | ▶ | sub _apply_role { | ||||||||
|
Subroutine
_apply_role: called CC=3 SCAR=11.0
| |||||||||||
| 36 | 8 | my ($target, $late) = @_; | |||||||||
| 37 | 8 | my $con = Moo->_constructor_maker_for($target); ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||
| 38 | 8 | ▶ | my $role = $late ? 'MooX::StrictConstructor::Role::Constructor::Late' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | : 'MooX::StrictConstructor::Role::Constructor'; | ||||||||||
| 40 | 8 | ▶ | Moo::Role->apply_roles_to_object($con, $role) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | unless Moo::Role::does_role($con, $role); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||