line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Base; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Base.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
37
|
|
|
37
|
|
235
|
use strict; |
|
37
|
|
|
|
|
65
|
|
|
37
|
|
|
|
|
1237
|
|
8
|
37
|
|
|
37
|
|
2682
|
use warnings; |
|
37
|
|
|
|
|
69
|
|
|
37
|
|
|
|
|
1214
|
|
9
|
37
|
|
|
37
|
|
202
|
use Carp qw/ croak /; |
|
37
|
|
|
|
|
84
|
|
|
37
|
|
|
|
|
2301
|
|
10
|
37
|
|
|
37
|
|
249
|
use base qw/ Class::Data::Inheritable /; |
|
37
|
|
|
|
|
89
|
|
|
37
|
|
|
|
|
61199
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION= '3.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
{ |
15
|
37
|
|
|
37
|
|
16299
|
no strict 'refs'; ## no critic. |
|
37
|
|
|
|
|
74
|
|
|
37
|
|
|
|
|
1151
|
|
16
|
37
|
|
|
37
|
|
191
|
no warnings 'redefine'; |
|
37
|
|
|
|
|
75
|
|
|
37
|
|
|
|
|
27187
|
|
17
|
|
|
|
|
|
|
sub mk_accessors { |
18
|
42
|
|
|
42
|
1
|
113
|
my $proto= shift; |
19
|
42
|
|
50
|
|
|
628
|
my $class= ref($proto) || $proto || return 0; |
20
|
42
|
|
|
|
|
117
|
for my $method (@_) { |
21
|
92
|
50
|
|
|
|
1006
|
next if $class->can($method); |
22
|
92
|
|
|
|
|
440
|
*{"${class}::${method}"}= sub { |
23
|
0
|
|
|
0
|
|
|
my $self= shift; |
24
|
0
|
0
|
|
|
|
|
@_ ? $self->{$method}= shift : $self->{$method}; |
25
|
92
|
|
|
|
|
353
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ e parameters /); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
*params= \¶meters; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
|
my $class= shift; |
35
|
0
|
|
0
|
|
|
|
my $e = shift || croak q{ I want egg context. }; |
36
|
0
|
|
0
|
|
|
|
my $param= shift || ($_[0] ? ($_[1] ? {@_}: $_[0]): {}); |
37
|
0
|
|
|
|
|
|
bless { e=> $e, parameters=> $param }, $class; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
sub param { |
40
|
0
|
|
|
0
|
1
|
|
my $self= shift; |
41
|
0
|
0
|
|
|
|
|
return keys %{$self->parameters} unless @_; |
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $pm= $self->parameters; |
43
|
0
|
0
|
|
|
|
|
return do { defined($pm->{$_[0]}) ? $pm->{$_[0]} : '' } if @_ < 2; |
|
0
|
0
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$pm->{$_[0]}= $_[1]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
sub error { |
47
|
0
|
|
|
0
|
1
|
|
my $self= shift; |
48
|
0
|
0
|
|
|
|
|
my $msg = $_[0] ? ($_[1] ? [@_]: ref($_[0]) eq 'ARRAY' ? $_[0]: [$_[0]]) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
49
|
|
|
|
|
|
|
: ['Internal Error.']; |
50
|
0
|
0
|
|
|
|
|
if (my $error= $self->{errstr}) { |
51
|
0
|
|
|
|
|
|
splice @$error, @$error, 0, @$msg; |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
|
$self->{errstr}= $msg; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
sub errstr { |
58
|
0
|
0
|
|
0
|
1
|
|
return 0 unless $_[0]->{errstr}; |
59
|
0
|
0
|
|
|
|
|
wantarray ? @{$_[0]->{errstr}}: join(', ', @{$_[0]->{errstr}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
sub config { |
62
|
0
|
|
|
0
|
1
|
|
my $self= shift; |
63
|
|
|
|
|
|
|
return @_ ? do { |
64
|
0
|
0
|
|
|
|
|
unless ($self->can('_config')) { |
65
|
0
|
|
0
|
|
|
|
my $class= ref($self) || $self; |
66
|
0
|
|
|
|
|
|
$class->mk_classdata('_config') ; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
|
|
|
|
$self->_config($_[0] ? ($_[1] ? {@_}: $_[0]): {}); |
|
|
0
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
}: do { |
70
|
0
|
0
|
|
|
|
|
$self->can('_config') ? $self->_config: (undef); |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
sub config_to { |
74
|
0
|
|
|
0
|
1
|
|
my $self= shift; |
75
|
0
|
|
|
|
|
|
my $p_class= join '::', ($self->e->project_name, @_); |
76
|
0
|
0
|
|
|
|
|
$p_class->can('config') ? $p_class->config : (undef); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Egg::Base - Generic base class for Egg. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
package Hoge; |
90
|
|
|
|
|
|
|
use base qw/Egg::Base/; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
It is a general base class for Egg. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
I think it is convenient when using it by the handler etc. of the plugin. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 METHODS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 mk_accessors ([CREATE_METHODS]) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L<Class::Accessor> The thing considerably is done. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ hoge boo /); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 new ([EGG_CONTEXT], [PARAM_HASH_REF]) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
General constructor for Egg application. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The object of the project is always necessary for EGG_CONTEXT. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Parameters is set at the same time as giving PARAM_HASH_REF. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $app= Hoge->new($e, { zoo=> 1 }); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 e |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
It is an accessor to the project object. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$app->e; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 parameters |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
It is an accessor to the parameter. It is the one that relates to PARAM_HASH_REF |
125
|
|
|
|
|
|
|
passed to the constructor. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $param= $app->parameters; |
128
|
|
|
|
|
|
|
print $param->{zoo}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over 4 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * Alias = params |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=back |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 param ([KEY], [VALUE]) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
When the argument is omitted, the list of the key registered in parameters is |
139
|
|
|
|
|
|
|
returned. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
When KEY is given, the value of parameters-E<gt>{KEY} is returned. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
When VALUE is given, the value is set in parameters-E<gt>{KEY}. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my @key_list= $app->param; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
print $app->param('zoo'); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$app->param('boo' => 'abc'); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 config ([CONFIG]) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The method of the relation to the class of '_config' is generated when CONFIG |
154
|
|
|
|
|
|
|
is given, and CONFIG is set in the method. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
When CONFIG is omitted, the content of the method of '_config' is returned. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$class->config({ |
159
|
|
|
|
|
|
|
........... |
160
|
|
|
|
|
|
|
..... |
161
|
|
|
|
|
|
|
}); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 config_to ([NAME_LIST]) |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The content of 'Config' of the class that generates it with the project name and |
166
|
|
|
|
|
|
|
NAME_LIST is returned. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# MyApp::Model::ComponentName->config is acquired. |
169
|
|
|
|
|
|
|
my $config= $app->config_to(qw/ Model ComponentName /); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 error ([MESSAGE]) |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
MESSAGE is set in errstr. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This method always returns 0. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Even if ARRAY is given to MESSAGE, it is treatable well. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
$app->error('Internal Error'); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 errstr |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
For reference to value set with error. The value cannot be set. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
If the receiver of the value has received it with ARRAY, the list is returned. |
186
|
|
|
|
|
|
|
The character string of ',' delimitation is returned if it receives it with SCALAR. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
my @error_list= $hoge->errstr; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my $error_string= $hoge->errstr; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 SEE ALSO |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L<Egg::Release>, |
195
|
|
|
|
|
|
|
L<Class::Data::Inheritable>, |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
206
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
207
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|