AttributeShortcuts.pm

filter: Statementstmt 100% 51 / 51 Branchbran 90.0% 9 / 10 Conditioncond 70.0% 7 / 10 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 91.0% 81 / 89 CC 11 SCAR 15.4
CC
11
Cov
94%
init_meta
9.2
import
3.0
BEGIN
1.0
CRAP 4.6
↑ Summary AttributeShortcuts/Trait/Attribute.pm »
1 #
2 # This file is part of MooseX-AttributeShortcuts
3 #
4 # This software is Copyright (c) 2017, 2015, 2014, 2013, 2012, 2011 by Chris Weyl.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package MooseX::AttributeShortcuts;
11 29 our $AUTHORITY = 'cpan:RSRCHBOY';
12 # git description: 0.036-2-g03ef7bc
13 29 $MooseX::AttributeShortcuts::VERSION = '0.037';
14  
15 # ABSTRACT: Shorthand for common attribute options
16  
17 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 29 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 29 ▶use Moose 1.14 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 29 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 29 ▶use Moose::Meta::TypeConstraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 29 ▶use Moose::Util::MetaRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 29 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 29 ▶use MooseX::AttributeShortcuts::Trait::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 29 ▶use MooseX::AttributeShortcuts::Trait::Role::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 29 my ($import, $unimport, $init_meta) = Moose::Exporter->build_import_methods(
32 install => [ 'unimport' ],
33 trait_aliases => [
34 [ 'MooseX::AttributeShortcuts::Trait::Attribute' => 'Shortcuts' ],
35 ],
36 );
37  
38 29 my $role_params;
39  
40 32 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
41 32 my ($class, %args) = @_;
42  
43 32 $role_params = {};
44 96 ▶ do { $role_params->{$_} = delete $args{"-$_"} if exists $args{"-$_"} }
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"-$_"} 2 94 96
45 32 for qw{ writer_prefix builder_prefix prefixes };
46  
47 32 @_ = ($class, %args);
48 32 goto &$import;
49 }
50  
51 33 ▶sub init_meta {
Subroutine init_meta: called CC=9 SCAR=22.2
Pod undocumented
52 33 my ($class_name, %args) = @_;
53 33 ▶ my $params = delete $args{role_params} || $role_params || undef;
Condition80%4/5
delete $args{'role_params'} || $role_params || undef
l!l
321
delete $args{"role_params"} or $role_params
l!l&&r!l&&!r
0321
MC/DC50%1/2
delete $args{'role_params'} || $role_params || undef
delete $args{"role_params"} $role_params
Truth table66%2/3
A or B
A= delete $args{"role_params"}B= $role_params
ABresult
1X1
011
000
54 33 undef $role_params;
55  
56 # Just in case we do ever start to get an $init_meta from ME
57 33 ▶ $init_meta->($class_name, %args)
Branch: 1 branch
BranchTrueFalseTotal
if $init_meta 0 33 33
58 if $init_meta;
59  
60 # make sure we have a metaclass instance kicking around
61 33 my $for_class = $args{for_class};
62 33 ▶ die "Class $for_class has no metaclass!"
Branch: 1 branch
BranchTrueFalseTotal
unless Class::MOP::class_of($for_class) 1 32 33
63 unless Class::MOP::class_of($for_class);
64  
65 # If we're given parameters to pass on to construct a role with, we build
66 # it out here rather than pass them on and allowing apply_metaroles() to
67 # handle it, as there are Very Loud Warnings about how parameterized roles
68 # are non-cacheable when generated on the fly.
69  
70 ### $params
71 32 ▶ my $trait
Branch: 1 branch
BranchTrueFalseTotal
$params && scalar keys %$params ? : 2 30 32
Condition50%1/2
$params and scalar keys %$params
!ll
032
MC/DC0%0/1
$params and scalar keys %$params
$params
Truth table50%1/2
A
A= $params
Aresult
00
11
72 = ($params && scalar keys %$params)
73 ? MooseX::AttributeShortcuts::Trait::Attribute
74 ->meta
75 ->generate_role(parameters => $params)
76 : 'MooseX::AttributeShortcuts::Trait::Attribute'
77 ;
78  
79 my $role_attribute_trait
80 = ($params && exists $params->{builder_prefix})
81 ? MooseX::AttributeShortcuts::Trait::Role::Attribute
82 ->meta
83 ->generate_role(
84 parameters => { builder_prefix => $params->{builder_prefix} },
85 )
86 32 ▶ : 'MooseX::AttributeShortcuts::Trait::Role::Attribute'
Branch: 1 branch
BranchTrueFalseTotal
$params && exists $params->{'builder_prefix'} ? : 1 31 32
Condition66%2/3
$params and exists $params->{"builder_prefix"}
!ll&&!rl&&r
0311
MC/DC50%1/2
$params and exists $params->{"builder_prefix"}
$params exists $params->{"builder_prefix"}
Truth table66%2/3
A and B
A= $paramsB= exists $params->{"builder_prefix"}
ABresult
0X0
100
111
87 ;
88  
89 32 Moose::Util::MetaRole::apply_metaroles(
90 # TODO add attribute trait here to create builder method if found
91 for => $for_class,
92 class_metaroles => { attribute => [ $trait ] },
93 role_metaroles => {
94 applied_attribute => [ $trait ],
95 # attribute => [ 'MooseX::AttributeShortcuts::Trait::Role::Attribute' ],
96 attribute => [ $role_attribute_trait ],
97 },
98 parameter_metaroles => { applied_attribute => [ $trait ] },
99 parameterized_role_metaroles => { applied_attribute => [ $trait ] },
100 );
101  
102 32 return Class::MOP::class_of($for_class);
103 }
104  
105 29 1;
106  
107 __END__
↑ Summary AttributeShortcuts/Trait/Attribute.pm »