| 1 | package CatalystX::ComponentsFromConfig::Role::AdaptorRole; | ||||||||||||||||||||||||||||
| 2 | 2 | $CatalystX::ComponentsFromConfig::Role::AdaptorRole::VERSION = '1.006'; | |||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||
| 4 | 2 | $CatalystX::ComponentsFromConfig::Role::AdaptorRole::DIST = 'CatalystX-ComponentsFromConfig'; | |||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MooseX::Role::Parameterized; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Moose::Util 'with_traits'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use MooseX::Types::Moose qw/ HashRef ArrayRef Str /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use MooseX::Types::Common::String qw/LowerCaseSimpleStr/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use MooseX::Types::LoadableClass qw/LoadableClass/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # ABSTRACT: parameterised role for trait-aware component adaptors | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | parameter component_type => ( | |||||||||||||||||||||||||||
| 18 | isa => LowerCaseSimpleStr, | ||||||||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | ▶ | sub _format_args { | ||||||||||||||||||||||||||
|
Subroutine
_format_args: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 23 | 4 | my ($format, $args) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | return $format eq 'hashref' ? $args | ||||||||||||||||||||||||||||
| 26 | 4 | ▶ | : $format eq 'list' ? %{$args} | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 27 | : die "Invalid args_format '$format'"; | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | ▶ | role { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 4 | my $params = shift; | |||||||||||||||||||||||||||
| 32 | 4 | my $type = ucfirst($params->component_type); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | has class => ( | |||||||||||||||||||||||||||
| 36 | isa => LoadableClass, | ||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||||||||||
| 39 | coerce => 1, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | has args => ( | ||||||||||||||||||||||||||||
| 44 | isa => HashRef, | ||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | 4 | ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | has args_format => ( | |||||||||||||||||||||||||||
| 51 | isa => enum([qw(hashref list)]), | ||||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||
| 53 | default => 'hashref', | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | has traits => ( | |||||||||||||||||||||||||||
| 58 | isa => ArrayRef[Str], | ||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | ▶ | around COMPONENT => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 63 | 4 | my ($orig, $class, $app, @rest) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | my $self = $class->$orig($app,@rest); | |||||||||||||||||||||||||||
| 66 | 4 | my $other_class = $self->class; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | unless ($other_class->can('meta')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | Moose->init_meta( | |||||||||||||||||||||||||||
| 70 | for_class => $other_class, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | if ($self->traits) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 3 | ▶ | if (not $other_class->can('new_with_traits')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | my $new_class = with_traits( | |||||||||||||||||||||||||||
| 77 | $other_class, | ||||||||||||||||||||||||||||
| 78 | 'MooseX::Traits::Pluggable', | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | my $original_other_class = $other_class; | |||||||||||||||||||||||||||
| 82 | 2 | $other_class = $new_class; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | $new_class->meta->add_method( | ||||||||||||||||||||||||||||
| 85 | 2 | ▶ | _trait_namespace => sub { | ||||||||||||||||||||||||||
|
Subroutine
_trait_namespace: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 86 | 2 | my ($other_self) = @_; | |||||||||||||||||||||||||||
| 87 | 2 | my $class = $original_other_class; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | if ($class =~ s/^\Q$app//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | my @list; | |||||||||||||||||||||||||||
| 91 | 1 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$class =~ s/::\w+$// and $class
MC/DC50%1/2
$class =~ s/::\w+$// and $class
$class =~ s/::\w+$//
$class
Truth table66%2/3
A and B
A= $class =~ s/::\w+$//B= $class
| |||||||||||||||||||||||||||||
| 92 | 2 | push(@list, "${app}::TraitFor" . $class) | |||||||||||||||||||||||||||
| 93 | } while ($class =~ s/::\w+$// && $class); | ||||||||||||||||||||||||||||
| 94 | 1 | push(@list, "${app}::TraitFor::${type}" . $class); | |||||||||||||||||||||||||||
| 95 | 1 | return \@list; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 1 | return $class . '::TraitFor'; | |||||||||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||||||||
| 99 | 2 | ); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | return $other_class->new_with_traits(_format_args $self->args_format, { | ||||||||||||||||||||||||||||
| 102 | traits => $self->traits, | ||||||||||||||||||||||||||||
| 103 | 3 | %{ $self->args }, | |||||||||||||||||||||||||||
| 104 | }); | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 1 | return $other_class->new(_format_args $self->args_format, $self->args); | |||||||||||||||||||||||||||
| 107 | 4 | }; | |||||||||||||||||||||||||||
| 108 | 2 | }; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||