| 1 | 8 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 0 | ▶ | BEGIN { if ($] < 5.010000) { require UNIVERSAL::DOES } }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package MooX::Traits::Util; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 10 | 8 | our $VERSION = '0.005'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Exporter::Shiny qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | new_class_with_traits | ||||||||||||||||||||||||||||
| 14 | new_class_with_traits_one_by_one | ||||||||||||||||||||||||||||
| 15 | 8 | ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 8 | my @keepsies; | |||||||||||||||||||||||||||
| 18 | my $parameterize_role = sub | ||||||||||||||||||||||||||||
| 19 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||
| 20 | 8 | my ($class, $trait, $params) = @_; | |||||||||||||||||||||||||||
| 21 | 8 | ▶ | return $trait unless @_ == 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | require Module::Runtime; | |||||||||||||||||||||||||||
| 24 | 8 | Module::Runtime::use_package_optimistically($trait); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 8 | ▶ | if ( $INC{'MooseX/Role/Parameterized.pm'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 4 | require Moose::Util; | |||||||||||||||||||||||||||
| 29 | 4 | my $meta = Moose::Util::find_meta($trait); | |||||||||||||||||||||||||||
| 30 | 4 | ▶ | if ($meta->can('generate_role')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 3 | my $generated = $meta->generate_role(parameters => $params); | |||||||||||||||||||||||||||
| 33 | 3 | push @keepsies, $generated; # prevent cleanup | |||||||||||||||||||||||||||
| 34 | 3 | return $generated->name; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 5 | ▶ | if ( $trait->can("make_variant") ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 3 | require Package::Variant; | |||||||||||||||||||||||||||
| 41 | 3 | ▶ | return "Package::Variant"->build_variant_of( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | $trait, | ||||||||||||||||||||||||||||
| 43 | ref($params) eq q(ARRAY) ? @$params : | ||||||||||||||||||||||||||||
| 44 | ref($params) eq q(HASH) ? %$params : | ||||||||||||||||||||||||||||
| 45 | $$params, | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 2 | return $trait; | |||||||||||||||||||||||||||
| 50 | 8 | }; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | my $looks_like_params = sub | ||||||||||||||||||||||||||||
| 53 | 43 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 54 | 43 | my $thing = $_[0]; | |||||||||||||||||||||||||||
| 55 | 43 | ▶ | return !!0 if not ref $thing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 8 | require Scalar::Util; | |||||||||||||||||||||||||||
| 57 | 8 | ▶ | return !!0 if Scalar::Util::blessed($thing); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 8 | return !!1; | |||||||||||||||||||||||||||
| 59 | 8 | }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub resolve_traits | ||||||||||||||||||||||||||||
| 62 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
resolve_traits: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 33 | my ($class, @args) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 33 | ▶ | my $ns = $class->DOES('MooX::Traits') ? $class->_trait_namespace : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 33 | ▶ | $ns = defined($ns) ? "$ns\::" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 33 | my @traits; | |||||||||||||||||||||||||||
| 69 | 33 | ▶ | while (@args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 41 | my $trait = shift(@args); | |||||||||||||||||||||||||||
| 72 | 41 | ▶ | $trait = $trait =~ /\A\+(.+)\z/ ? $1 : "$ns$trait"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 41 | ▶ | push @traits => ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | $looks_like_params->($args[0]) | ||||||||||||||||||||||||||||
| 76 | ? $parameterize_role->($class, $trait, shift(@args)) | ||||||||||||||||||||||||||||
| 77 | : $trait | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 33 | return @traits; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | my $toolage = sub | ||||||||||||||||||||||||||||
| 84 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 85 | 33 | my $class = shift; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 33 | ▶ | if ($INC{"Moo.pm"} and $Moo::MAKERS{$class}{is_class}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$INC{"Moo.pm"} and $Moo::MAKERS{$class}{"is_class"}
MC/DC100%2/2
$INC{"Moo.pm"} and $Moo::MAKERS{$class}{"is_class"}
$INC{"Moo.pm"}
$Moo::MAKERS{$class}{"is_class"}
Truth table100%3/3
A and B
A= $INC{"Moo.pm"}B= $Moo::MAKERS{$class}{"is_class"}
| |||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 23 | require Moo::Role; | |||||||||||||||||||||||||||
| 90 | 23 | return "Moo::Role"; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 10 | ▶ | if ($INC{"Moo/Role.pm"}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 2 | return "Moo::Role"; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | "Role::Tiny"; | |||||||||||||||||||||||||||
| 99 | 8 | }; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub new_class_with_traits | ||||||||||||||||||||||||||||
| 102 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new_class_with_traits: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 33 | my ($class, @traits) = @_; | |||||||||||||||||||||||||||
| 104 | 33 | $class->$toolage->create_class_with_roles( | |||||||||||||||||||||||||||
| 105 | $class, | ||||||||||||||||||||||||||||
| 106 | resolve_traits($class, @traits), | ||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub new_class_with_traits_one_by_one | ||||||||||||||||||||||||||||
| 111 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new_class_with_traits_one_by_one: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 2 | my ($class, @traits) = @_; | |||||||||||||||||||||||||||
| 113 | 2 | ▶ | while (@traits) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 2 | my @trait = shift(@traits); | |||||||||||||||||||||||||||
| 116 | 2 | ▶ | push @trait, shift(@traits) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | if $looks_like_params->($traits[0]); | ||||||||||||||||||||||||||||
| 118 | 2 | $class = new_class_with_traits($class, @trait); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | return $class; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 8 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||