| 1 | package Catalyst::Model::Orochi; | ||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use Orochi; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | our $VERSION = '0.00002'; | ||||||||||
| 7 | our $AUTHORITY = 'cpan:DMAKI'; | ||||||||||
| 8 | |||||||||||
| 9 | extends 'Catalyst::Model'; | ||||||||||
| 10 | |||||||||||
| 11 | has assembler => ( | ||||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | isa => 'Orochi', | ||||||||||
| 14 | lazy_build => 1, | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | has classes => ( | ||||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | isa => 'ArrayRef', | ||||||||||
| 20 | predicate => 'has_classes', | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | has injections => ( | ||||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | isa => 'HashRef', | ||||||||||
| 26 | predicate => 'has_injections', | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | has namespaces => ( | ||||||||||
| 30 | is => 'ro', | ||||||||||
| 31 | isa => 'ArrayRef', | ||||||||||
| 32 | predicate => 'has_namespaces' | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | has prefix => ( | ||||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | isa => 'Str', | ||||||||||
| 38 | predicate => 'has_prefix', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub _build_assembler { | ||||||||
|
Subroutine
_build_assembler: not called CC=2 SCAR=17.9
| |||||||||||
| 42 | 0 | my $self = shift; | |||||||||
| 43 | 0 | my %args; | |||||||||
| 44 | 0 | ▶ | if ($self->has_prefix) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | $args{prefix} = $self->prefix; | |||||||||
| 46 | } | ||||||||||
| 47 | 0 | return Orochi->new(%args); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub BUILD { | ||||||||||
| 51 | my $self = shift; | ||||||||||
| 52 | |||||||||||
| 53 | foreach my $component qw(injections classes namespaces) { | ||||||||||
| 54 | my $predicate = "has_$component"; | ||||||||||
| 55 | my $setup = "setup_$component"; | ||||||||||
| 56 | if ( $self->$predicate() ) { | ||||||||||
| 57 | $self->$setup(); | ||||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | return $self; | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | sub setup_injections { | ||||||||||
| 65 | my $self = shift; | ||||||||||
| 66 | my $assembler = $self->assembler; | ||||||||||
| 67 | while ( my($name, $value) = each %{ $self->injections }) { | ||||||||||
| 68 | if ( ! blessed $value ) { | ||||||||||
| 69 | $value = Orochi::Injection::Literal->new(value => $value); | ||||||||||
| 70 | } | ||||||||||
| 71 | $assembler->inject($name, $value); | ||||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub setup_classes { | ||||||||||
| 76 | my $self = shift; | ||||||||||
| 77 | my $assembler = $self->assembler; | ||||||||||
| 78 | foreach my $class ( @{ $self->classes } ) { | ||||||||||
| 79 | $assembler->inject_class( $class ); | ||||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub setup_namespaces { | ||||||||||
| 84 | my $self = shift; | ||||||||||
| 85 | my $assembler = $self->assembler; | ||||||||||
| 86 | foreach my $namespace ( @{ $self->namespaces } ) { | ||||||||||
| 87 | $assembler->inject_namespace( $namespace ); | ||||||||||
| 88 | } | ||||||||||
| 89 | return $self; | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | sub get { | ||||||||||
| 93 | my $self = shift; | ||||||||||
| 94 | $self->assembler->get(@_); | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | __PACKAGE__->meta->make_immutable(); | ||||||||||
| 98 | |||||||||||
| 99 | 1; | ||||||||||
| 100 | |||||||||||
| 101 | __END__ | ||||||||||