Bolts.pm

filter: Statementstmt 99.0% 100 / 101 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.5% 28 / 29 Podpod 80.0% 8 / 10 totaltotal 97.3% 144 / 148 CC 6 SCAR 3.2
CC
6
Cov
99%
option
3.0
__ANON__
2.0
_bag_meta
2.0
CRAP 1.4
« Bolts/Meta/Class/Trait/Locator.pm ↑ Summary Bolts/Meta/Locator.pm »
1 package Bolts;
2 11 $Bolts::VERSION = '0.143171';
3 # ABSTRACT: An Inversion of Control framework for Perl
4  
5 11 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Register attribute traits
9 11 ▶use Bolts::Meta::Attribute::Trait::Initializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶use Class::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Moose::Util::MetaRole ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Moose::Util::TypeConstraints ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 11 ▶use Bolts::Util qw( locator_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use Bolts::Blueprint::Given;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use Bolts::Blueprint::Literal;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use Bolts::Blueprint::Built;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 11 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 11 our @CARP_NOT = qw( Moose::Exporter );
26  
27 # Ugly, but so far... necessary...
28 11 our $GLOBAL_FALLBACK_META_LOCATOR = 'Bolts::Meta::Locator';
29  
30 11 my @BAG_META;
31  
32 11 Moose::Exporter->setup_import_methods(
33 class_metaroles => {
34 class => [
35 'Bolts::Meta::Class::Trait::Locator',
36 'Bolts::Meta::Class::Trait::Bag',
37 ],
38 },
39 base_class_roles => [ 'Bolts::Role::SelfLocator' ],
40 with_meta => [ qw(
41 artifact bag builder contains dep option self such_that_each value
42 ) ],
43 also => 'Moose',
44 );
45  
46 12 ▶sub init_meta {
Subroutine init_meta: called CC=1 SCAR=0.0
Pod undocumented
47 12 my $class = shift;
48 12 my $meta = Moose->init_meta(@_);
49  
50 $meta->add_attribute(__top => (
51 reader => '__top',
52 required => 1,
53 22 ▶ default => sub { shift },
Subroutine __ANON__: called CC=1 SCAR=0.0
54 12 lazy => 1,
55 weak_ref => 1,
56 ));
57  
58 12 return $meta;
59 }
60  
61 60 ▶sub _bag_meta {
Subroutine _bag_meta: called CC=2 SCAR=6.9
62 60 my ($meta) = @_;
63  
64 60 ▶ $meta = $BAG_META[-1] if @BAG_META;
Branch: 1 branch
BranchTrueFalseTotal
if @BAG_META 9 51 60
65  
66 60 return $meta;
67 }
68  
69  
70 45 ▶sub artifact {
Subroutine artifact: called CC=1 SCAR=0.0
Pod documented
71 45 my $meta = _bag_meta(shift);
72 45 my $artifact = Bolts::Util::artifact($meta, @_);
73 45 $meta->add_artifact(%$artifact);
74 45 return;
75 }
76  
77  
78 11 our @BAG_OF_BUILDING;
79 2 ▶sub bag {
Subroutine bag: called CC=1 SCAR=0.0
Pod documented
80 2 my ($meta, $name, $partial_def) = @_;
81  
82 2 $meta = _bag_meta($meta);
83  
84 2 my $def = $partial_def->($name);
85 $meta->add_artifact(
86 $name => Bolts::Artifact::Thunk->new(
87 15 ▶ thunk => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
88 15 my ($self, $bag, $name, %params) = @_;
89 15 return $def->name->new(
90 __parent => $bag,
91 %params,
92 );
93 },
94 )
95 2 );
96 }
97  
98 2 ▶sub contains(&;$) {
Subroutine contains: called CC=1 SCAR=0.0
Pod undocumented
99 2 my ($parent_meta, $code, $such_that_each) = @_;
100  
101 2 my $meta = _bag_meta($parent_meta);
102  
103 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
104 2 my ($name) = shift;
105  
106 2 my $parent = $meta->name;
107  
108 2 ▶ my $bag_meta = Bolts::Bag->start_bag(
Branch: 1 branch
BranchTrueFalseTotal
$such_that_each ? : 1 1 2
109 package => "${parent}::$name",
110 ($such_that_each ? (such_that_each => $such_that_each) : ()),
111 );
112 2 push @BAG_META, $bag_meta;
113  
114 $bag_meta->add_attribute(__parent => (
115 reader => '__parent',
116 required => 1,
117 0 ▶ default => sub { Carp::confess('why are we here?') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
118 2 weak_ref => 1,
119 ));
120  
121 2 $bag_meta->add_artifact(
122 __top => Bolts::Artifact->new(
123 meta_locator => $bag_meta,
124 name => '__top',
125 blueprint => $bag_meta->acquire('blueprint', 'acquired', {
126 path => [ '__parent', '__top' ],
127 }),
128 scope => $bag_meta->acquire('scope', 'prototype'),
129 )
130 );
131  
132 2 $code->($bag_meta);
133  
134 2 pop @BAG_META;
135  
136 2 $bag_meta->finish_bag;
137  
138 2 return $bag_meta;
139 2 };
140 }
141  
142  
143 1 ▶sub such_that_each($) {
Subroutine such_that_each: called CC=1 SCAR=0.0
Pod documented
144 1 my ($meta, $params) = @_;
145 1 return $params;
146 }
147  
148  
149 2 ▶sub builder(&) {
Subroutine builder: called CC=1 SCAR=0.0
Pod documented
150 2 my ($meta, $code) = @_;
151 2 $meta = _bag_meta($meta);
152  
153 return {
154 2 blueprint => $meta->acquire('blueprint', 'built_injector', {
155 builder => $code,
156 }),
157 };
158 }
159  
160  
161 9 ▶sub dep($) {
Subroutine dep: called CC=2 SCAR=6.9
Pod documented
162 9 my ($meta, $path) = @_;
163 9 $meta = _bag_meta($meta);
164  
165 9 ▶ $path = [ $path ] unless ref $path eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $path eq "ARRAY" 4 5 9
166  
167 9 my @path = ('__top', @$path);
168  
169 return {
170 9 blueprint => $meta->acquire('blueprint', 'acquired', {
171 path => \@path,
172 }),
173 };
174 }
175  
176  
177 8 ▶sub option($) {
Subroutine option: called CC=3 SCAR=11.0
Pod documented
178 8 my ($meta, $p) = @_;
179  
180 8 my %bp = %$p;
181 8 my %ip;
182 8 for my $k (qw( isa does )) {
183 16 ▶ $ip{$k} = delete $bp{$k} if exists $bp{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $bp{$k} 8 8 16
184 }
185  
186 return {
187 8 %ip,
188 blueprint => $meta->acquire('blueprint', 'given', \%bp),
189 },
190 }
191  
192  
193 18 ▶sub value($) {
Subroutine value: called CC=1 SCAR=0.0
Pod documented
194 18 my ($meta, $value) = @_;
195  
196 return {
197 18 blueprint => $meta->acquire('blueprint', 'literal', {
198 value => $value,
199 }),
200 };
201 }
202  
203  
204 1 ▶sub self() {
Subroutine self: called CC=1 SCAR=0.0
Pod documented
205 1 my ($meta, $value) = @_;
206  
207 return {
208 1 blueprint => $meta->acquire('blueprint', 'parent_bag'),
209 };
210 }
211  
212  
213 11 1;
214  
215 __END__
« Bolts/Meta/Class/Trait/Locator.pm ↑ Summary Bolts/Meta/Locator.pm »