line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Model::Orochi; |
2
|
1
|
|
|
1
|
|
1862
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Orochi; |
4
|
|
|
|
|
|
|
use namespace::autoclean; |
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
|
|
|
|
|
|
|
sub _build_assembler { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
my %args; |
44
|
|
|
|
|
|
|
if ($self->has_prefix) { |
45
|
|
|
|
|
|
|
$args{prefix} = $self->prefix; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
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__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Catalyst::Model::Orochi - Catalyst-Orochi Integration |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# in your MyApp::Model::Orochi |
110
|
|
|
|
|
|
|
package MyApp::Model::Orochi; |
111
|
|
|
|
|
|
|
use Moose; |
112
|
|
|
|
|
|
|
use namespace::autoclean; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
extends 'Catalyst::Model::Orochi'; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# in your config (watch out for indentation, this is YAML) |
121
|
|
|
|
|
|
|
Model::Orochi: |
122
|
|
|
|
|
|
|
injections: # for literal values |
123
|
|
|
|
|
|
|
name01: value01 |
124
|
|
|
|
|
|
|
classes: |
125
|
|
|
|
|
|
|
- ClassName01 |
126
|
|
|
|
|
|
|
- ClassName02 |
127
|
|
|
|
|
|
|
namespaces: |
128
|
|
|
|
|
|
|
- Namespace01 |
129
|
|
|
|
|
|
|
- Namespace02 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# in your Catalyst code: |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my $value = $c->model('Orochi')->get('registered/path'); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This model integrates Orochi DI container with Catalyst. The same caveats from Orochi apply. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 CONFIGURATION KEYS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item B<injections> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
A hashref of literal values. Same as inject_literal() or Orochi::Injection::Literal |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item B<classes> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
A list of class names. These classes should be using MooseX::Orochi. If the class does not use, or have an ancestor that uses MooseX::Orochi, the class will be silently ignored |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item B<namespaces> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
A list of namespaces. Any class files found under the namespace that uses MooseX::Orochi will be included. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHOR |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Daisuke Maki C<< <daisuke@endeworks.jp> >> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 LICENSE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
162
|
|
|
|
|
|
|
under the same terms as Perl itself. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |