| 1 | package Bolts::Meta::Locator; | ||||||||||
| 2 | 11 | $Bolts::Meta::Locator::VERSION = '0.143171'; | |||||||||
| 3 | # ABSTRACT: Standard meta locator for Bolts | ||||||||||
| 4 | |||||||||||
| 5 | 11 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 11 | with qw( Bolts::Role::RootLocator ); | |||||||||
| 8 | |||||||||||
| 9 | 11 | ▶ | use Bolts::Artifact; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 11 | ▶ | use Bolts::Artifact::Thunk; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 11 | ▶ | use Bolts::Bag; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 11 | ▶ | use Bolts::Blueprint::Built; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 11 | ▶ | use Bolts::Blueprint::Factory; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 11 | ▶ | use Bolts::Blueprint::Given; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 11 | ▶ | use Bolts::Blueprint::Literal; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 11 | ▶ | use Bolts::Injector::Parameter::ByName; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 11 | ▶ | use Bolts::Scope::Prototype; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 11 | ▶ | use Bolts::Scope::Singleton; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 11 | ▶ | use Class::Load; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 325 | ▶ | sub root { $_[0] } | ||||||||
|
Subroutine
root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | 11 | has blueprint => ( | |||||||||
| 30 | is => 'ro', | ||||||||||
| 31 | isa => 'Object', | ||||||||||
| 32 | lazy_build => 1, | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | 19 | ▶ | sub _build_blueprint { | ||||||||
|
Subroutine
_build_blueprint: called CC=2 SCAR=6.9
| |||||||||||
| 36 | 19 | my $self = shift; | |||||||||
| 37 | |||||||||||
| 38 | 19 | my $bp = Bolts::Bag->start_bag( | |||||||||
| 39 | package => 'Bolts::Meta::Locator::Blueprint', | ||||||||||
| 40 | such_that_each => { | ||||||||||
| 41 | does => 'Bolts::Blueprint', | ||||||||||
| 42 | }, | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 19 | ▶ | return $bp->name->new if $bp->is_finished_bag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | $bp->add_artifact( | ||||||||||
| 48 | acquired => Bolts::Artifact::Thunk->new( | ||||||||||
| 49 | 38 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 38 | my ($self, $bag, %o) = @_; | |||||||||
| 51 | 38 | Class::Load::load_class('Bolts::Blueprint::Acquired'); | |||||||||
| 52 | 38 | Bolts::Blueprint::Acquired->new(%o); | |||||||||
| 53 | }, | ||||||||||
| 54 | 11 | ), | |||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | $bp->add_artifact( | ||||||||||
| 58 | given => Bolts::Artifact::Thunk->new( | ||||||||||
| 59 | 112 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 112 | my ($self, $bag, %o) = @_; | |||||||||
| 61 | 112 | Class::Load::load_class('Bolts::Blueprint::Given'); | |||||||||
| 62 | 112 | Bolts::Blueprint::Given->new(%o); | |||||||||
| 63 | }, | ||||||||||
| 64 | 11 | ), | |||||||||
| 65 | ); | ||||||||||
| 66 | |||||||||||
| 67 | $bp->add_artifact( | ||||||||||
| 68 | literal => Bolts::Artifact::Thunk->new( | ||||||||||
| 69 | 42 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 42 | my ($self, $bag, %o) = @_; | |||||||||
| 71 | 42 | Class::Load::load_class('Bolts::Blueprint::Literal'); | |||||||||
| 72 | 42 | Bolts::Blueprint::Literal->new(%o); | |||||||||
| 73 | }, | ||||||||||
| 74 | 11 | ), | |||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | $bp->add_artifact( | ||||||||||
| 78 | built => Bolts::Artifact::Thunk->new( | ||||||||||
| 79 | 46 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 80 | 46 | my ($self, $bag, %o) = @_; | |||||||||
| 81 | 46 | Class::Load::load_class('Bolts::Blueprint::Built'); | |||||||||
| 82 | 46 | Bolts::Blueprint::Built->new(%o); | |||||||||
| 83 | }, | ||||||||||
| 84 | 11 | ), | |||||||||
| 85 | ); | ||||||||||
| 86 | |||||||||||
| 87 | $bp->add_artifact( | ||||||||||
| 88 | built_injector => Bolts::Artifact::Thunk->new( | ||||||||||
| 89 | 4 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 90 | 4 | my ($self, $bag, %o) = @_; | |||||||||
| 91 | 4 | Class::Load::load_class('Bolts::Blueprint::BuiltInjector'); | |||||||||
| 92 | 4 | Bolts::Blueprint::BuiltInjector->new(%o); | |||||||||
| 93 | }, | ||||||||||
| 94 | 11 | ), | |||||||||
| 95 | ); | ||||||||||
| 96 | |||||||||||
| 97 | $bp->add_artifact( | ||||||||||
| 98 | factory => Bolts::Artifact::Thunk->new( | ||||||||||
| 99 | 24 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 100 | 24 | my ($self, $bag, %o) = @_; | |||||||||
| 101 | 24 | Class::Load::load_class('Bolts::Blueprint::Factory'); | |||||||||
| 102 | 24 | Bolts::Blueprint::Factory->new(%o); | |||||||||
| 103 | }, | ||||||||||
| 104 | 11 | ), | |||||||||
| 105 | ); | ||||||||||
| 106 | |||||||||||
| 107 | $bp->add_artifact( | ||||||||||
| 108 | parent_bag => Bolts::Artifact::Thunk->new( | ||||||||||
| 109 | 2 | ▶ | thunk => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 110 | 2 | my ($self, $bag, %o) = @_; | |||||||||
| 111 | 2 | Class::Load::load_class('Bolts::Blueprint::ParentBag'); | |||||||||
| 112 | 2 | Bolts::Blueprint::ParentBag->new(%o); | |||||||||
| 113 | }, | ||||||||||
| 114 | 11 | ), | |||||||||
| 115 | ); | ||||||||||
| 116 | |||||||||||
| 117 | 11 | $bp->finish_bag; | |||||||||
| 118 | |||||||||||
| 119 | 11 | return $bp->name->new; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | 11 | has inference => ( | |||||||||
| 124 | is => 'ro', | ||||||||||
| 125 | isa => 'ArrayRef', | ||||||||||
| 126 | lazy_build => 1, | ||||||||||
| 127 | ); | ||||||||||
| 128 | |||||||||||
| 129 | 6 | ▶ | sub _build_inference { | ||||||||
|
Subroutine
_build_inference: called CC=1 SCAR=0.0
| |||||||||||
| 130 | 6 | my $self = shift; | |||||||||
| 131 | |||||||||||
| 132 | 6 | my $singleton = $self->scope->singleton->get($self->scope); | |||||||||
| 133 | |||||||||||
| 134 | return [ | ||||||||||
| 135 | 6 | Bolts::Artifact->new( | |||||||||
| 136 | name => 'moose', | ||||||||||
| 137 | blueprint => Bolts::Blueprint::Factory->new( | ||||||||||
| 138 | class => 'Bolts::Inference::Moose', | ||||||||||
| 139 | ), | ||||||||||
| 140 | scope => $singleton, | ||||||||||
| 141 | ), | ||||||||||
| 142 | ]; | ||||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | |||||||||||
| 146 | 11 | has injector => ( | |||||||||
| 147 | is => 'ro', | ||||||||||
| 148 | isa => 'Object', | ||||||||||
| 149 | lazy_build => 1, | ||||||||||
| 150 | ); | ||||||||||
| 151 | |||||||||||
| 152 | 12 | ▶ | sub _build_injector { | ||||||||
|
Subroutine
_build_injector: called CC=2 SCAR=6.9
| |||||||||||
| 153 | 12 | my $self = shift; | |||||||||
| 154 | |||||||||||
| 155 | 12 | my $prototype = $self->scope->prototype->get($self->scope); | |||||||||
| 156 | |||||||||||
| 157 | 12 | my $parameter_name = Bolts::Artifact->new( | |||||||||
| 158 | name => 'parameter_name', | ||||||||||
| 159 | blueprint => Bolts::Blueprint::Factory->new( | ||||||||||
| 160 | class => 'Bolts::Injector::Parameter::ByName', | ||||||||||
| 161 | ), | ||||||||||
| 162 | scope => $prototype, | ||||||||||
| 163 | injectors => [ | ||||||||||
| 164 | Bolts::Injector::Parameter::ByName->new( | ||||||||||
| 165 | key => 'key', | ||||||||||
| 166 | blueprint => Bolts::Blueprint::Given->new( | ||||||||||
| 167 | required => 1, | ||||||||||
| 168 | ), | ||||||||||
| 169 | ), | ||||||||||
| 170 | Bolts::Injector::Parameter::ByName->new( | ||||||||||
| 171 | key => 'blueprint', | ||||||||||
| 172 | blueprint => Bolts::Blueprint::Given->new( | ||||||||||
| 173 | required => 1, | ||||||||||
| 174 | ), | ||||||||||
| 175 | ), | ||||||||||
| 176 | Bolts::Injector::Parameter::ByName->new( | ||||||||||
| 177 | key => 'does', | ||||||||||
| 178 | blueprint => Bolts::Blueprint::Given->new( | ||||||||||
| 179 | required => 0, | ||||||||||
| 180 | ), | ||||||||||
| 181 | ), | ||||||||||
| 182 | Bolts::Injector::Parameter::ByName->new( | ||||||||||
| 183 | key => 'isa', | ||||||||||
| 184 | blueprint => Bolts::Blueprint::Given->new( | ||||||||||
| 185 | required => 0, | ||||||||||
| 186 | ), | ||||||||||
| 187 | ), | ||||||||||
| 188 | Bolts::Injector::Parameter::ByName->new( | ||||||||||
| 189 | key => 'name', | ||||||||||
| 190 | blueprint => Bolts::Blueprint::Given->new( | ||||||||||
| 191 | required => 0, | ||||||||||
| 192 | ), | ||||||||||
| 193 | ), | ||||||||||
| 194 | ], | ||||||||||
| 195 | ); | ||||||||||
| 196 | |||||||||||
| 197 | 12 | my $bag = Bolts::Bag->start_bag( | |||||||||
| 198 | package => 'Bolts::Meta::Locator::Injector', | ||||||||||
| 199 | such_that_each => { | ||||||||||
| 200 | does => 'Bolts::Injector', | ||||||||||
| 201 | }, | ||||||||||
| 202 | ); | ||||||||||
| 203 | |||||||||||
| 204 | 12 | ▶ | return $bag->name->new if $bag->is_finished_bag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 205 | |||||||||||
| 206 | 6 | $bag->add_artifact( parameter_name => $parameter_name ); | |||||||||
| 207 | |||||||||||
| 208 | 6 | $bag->add_artifact( | |||||||||
| 209 | parameter_position => Bolts::Artifact->new( | ||||||||||
| 210 | name => 'parameter_position', | ||||||||||
| 211 | blueprint => Bolts::Blueprint::Factory->new( | ||||||||||
| 212 | class => 'Bolts::Injector::Parameter::ByPosition', | ||||||||||
| 213 | ), | ||||||||||
| 214 | infer => 'options', | ||||||||||
| 215 | scope => $prototype, | ||||||||||
| 216 | ), | ||||||||||
| 217 | ); | ||||||||||
| 218 | |||||||||||
| 219 | 6 | $bag->add_artifact( | |||||||||
| 220 | setter => Bolts::Artifact->new( | ||||||||||
| 221 | name => 'setter', | ||||||||||
| 222 | blueprint => Bolts::Blueprint::Factory->new( | ||||||||||
| 223 | class => 'Bolts::Injector::Setter', | ||||||||||
| 224 | ), | ||||||||||
| 225 | infer => 'options', | ||||||||||
| 226 | scope => $prototype, | ||||||||||
| 227 | ), | ||||||||||
| 228 | ); | ||||||||||
| 229 | |||||||||||
| 230 | 6 | $bag->add_artifact( | |||||||||
| 231 | store_array => Bolts::Artifact->new( | ||||||||||
| 232 | name => 'store_array', | ||||||||||
| 233 | blueprint => Bolts::Blueprint::Factory->new( | ||||||||||
| 234 | class => 'Bolts::Injector::Store::Array', | ||||||||||
| 235 | ), | ||||||||||
| 236 | infer => 'options', | ||||||||||
| 237 | scope => $prototype, | ||||||||||
| 238 | ), | ||||||||||
| 239 | ); | ||||||||||
| 240 | |||||||||||
| 241 | 6 | $bag->add_artifact( | |||||||||
| 242 | store_hash => Bolts::Artifact->new( | ||||||||||
| 243 | name => 'store_hash', | ||||||||||
| 244 | blueprint => Bolts::Blueprint::Factory->new( | ||||||||||
| 245 | class => 'Bolts::Injector::Store::Hash', | ||||||||||
| 246 | ), | ||||||||||
| 247 | infer => 'options', | ||||||||||
| 248 | scope => $prototype, | ||||||||||
| 249 | ), | ||||||||||
| 250 | ); | ||||||||||
| 251 | |||||||||||
| 252 | 6 | $bag->finish_bag; | |||||||||
| 253 | |||||||||||
| 254 | 6 | return $bag->name->new; | |||||||||
| 255 | } | ||||||||||
| 256 | |||||||||||
| 257 | |||||||||||
| 258 | 11 | has scope => ( | |||||||||
| 259 | is => 'ro', | ||||||||||
| 260 | isa => 'Object', | ||||||||||
| 261 | lazy_build => 1, | ||||||||||
| 262 | ); | ||||||||||
| 263 | |||||||||||
| 264 | 19 | ▶ | sub _build_scope { | ||||||||
|
Subroutine
_build_scope: called CC=2 SCAR=6.9
| |||||||||||
| 265 | 19 | my $self = shift; | |||||||||
| 266 | |||||||||||
| 267 | 19 | my $singleton = Bolts::Scope::Singleton->new; | |||||||||
| 268 | 19 | my $prototype = Bolts::Scope::Prototype->new; | |||||||||
| 269 | |||||||||||
| 270 | 19 | my $prototype_artifact = Bolts::Artifact->new( | |||||||||
| 271 | name => 'prototype', | ||||||||||
| 272 | blueprint => Bolts::Blueprint::Literal->new( | ||||||||||
| 273 | value => $prototype, | ||||||||||
| 274 | ), | ||||||||||
| 275 | scope => $singleton, | ||||||||||
| 276 | ); | ||||||||||
| 277 | |||||||||||
| 278 | 19 | my $bag = Bolts::Bag->start_bag( | |||||||||
| 279 | package => 'Bolts::Meta::Locator::Scope', | ||||||||||
| 280 | such_that_each => { | ||||||||||
| 281 | does => 'Bolts::Scope', | ||||||||||
| 282 | }, | ||||||||||
| 283 | ); | ||||||||||
| 284 | |||||||||||
| 285 | 19 | ▶ | return $bag->name->new if $bag->is_finished_bag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 286 | |||||||||||
| 287 | 19 | $bag->add_artifact(_ => $prototype_artifact); | |||||||||
| 288 | 19 | $bag->add_artifact(prototype => $prototype_artifact); | |||||||||
| 289 | |||||||||||
| 290 | 19 | $bag->add_artifact( | |||||||||
| 291 | singleton => Bolts::Artifact->new( | ||||||||||
| 292 | name => 'singleton', | ||||||||||
| 293 | blueprint => Bolts::Blueprint::Literal->new( | ||||||||||
| 294 | value => $singleton, | ||||||||||
| 295 | ), | ||||||||||
| 296 | scope => $singleton, | ||||||||||
| 297 | ), | ||||||||||
| 298 | ); | ||||||||||
| 299 | |||||||||||
| 300 | 19 | return $bag->name->new; | |||||||||
| 301 | } | ||||||||||
| 302 | |||||||||||
| 303 | 11 | 1; | |||||||||
| 304 | |||||||||||
| 305 | __END__ | ||||||||||