| 1 | package oCLI::Context; | ||||||||||
| 2 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Package::Stash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Module::Runtime qw( use_module ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use oCLI::Plugin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | has req => ( | |||||||||
| 8 | is => 'rw', | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | has plugin => ( | ||||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | lazy => 1, | ||||||||||
| 14 | 0 | ▶ | builder => sub { oCLI::Plugin->new }, | ||||||||
|
Subroutine
_build_plugin: not called CC=1 SCAR=6.9
| |||||||||||
| 15 | 1 | ); | |||||||||
| 16 | |||||||||||
| 17 | has stash => ( | ||||||||||
| 18 | is => 'rw', | ||||||||||
| 19 | 0 | ▶ | default => sub { return +{} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | 1 | ); | |||||||||
| 21 | |||||||||||
| 22 | 1 | has root => ( | |||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub trace { | ||||||||
|
Subroutine
trace: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 27 | 0 | my ( $self, $message ) = @_; | |||||||||
| 28 | |||||||||||
| 29 | 0 | my ( $package, $filename, $line ) = caller; | |||||||||
| 30 | 0 | ▶ | if ( exists $self->req->{overrides}->{trace} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | print "TRACE[$package:$line]> $message\n"; | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub model { | ||||||||
|
Subroutine
model: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||
| 36 | 0 | my ( $self, $name ) = @_; | |||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | if ( exists $self->{model}->{name} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | $self->trace("model($name) requested and memoized object returned."); | |||||||||
| 41 | 0 | return $self->{model}->{name}; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | $self->trace("Initial request for model($name)"); | |||||||||
| 45 | |||||||||||
| 46 | 0 | my $stash = (Package::Stash->new( $self->root )->get_symbol('%stash')); | |||||||||
| 47 | |||||||||||
| 48 | # Inject context into arguments if context is set. | ||||||||||
| 49 | 0 | ▶ | if ( exists $stash->{model}{$name}{context} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | die "Can only inject context argument into hash style arguments." | ||||||||||
| 51 | 0 | ▶ | if ref($stash->{model}{$name}{args}) ne 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | $stash->{model}{$name}{args}{$stash->{model}{$name}{context}} = $self; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | if ( exists $stash->{model}->{$name} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | return use_module( $stash->{model}->{$name}->{class} )->new( | ||||||||||
| 57 | ref($stash->{model}->{$name}->{args}) eq 'ARRAY' | ||||||||||
| 58 | 0 | ▶ | ? @{$stash->{model}->{$name}->{args}} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | : ref($stash->{model}->{$name}->{args}) eq 'HASH' | ||||||||||
| 60 | 0 | ? %{$stash->{model}->{$name}->{args}} | |||||||||
| 61 | : $stash->{model}->{$name}->{args} | ||||||||||
| 62 | 0 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | } else { | ||||||||||
| 64 | 0 | die "Error: Couldn't load model $name\n"; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | 1; | |||||||||