line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::ENV; |
2
|
1
|
|
|
1
|
|
52301
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
252
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.02; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub get_env_value { |
7
|
0
|
|
|
0
|
1
|
|
my ($c,$name) = @_; |
8
|
0
|
|
|
|
|
|
my ($value,$env); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $get = sub { |
11
|
0
|
|
|
0
|
|
|
my $name = shift; |
12
|
0
|
|
|
|
|
|
my $env = shift; |
13
|
0
|
|
|
|
|
|
my $res; |
14
|
0
|
0
|
0
|
|
|
|
if( defined $name && defined $env->{$name} ){ |
15
|
0
|
|
|
|
|
|
$res = $env->{$name}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
else { |
18
|
0
|
|
|
|
|
|
$res = $env; |
19
|
|
|
|
|
|
|
} |
20
|
0
|
|
|
|
|
|
return $res; |
21
|
0
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
if( ref $c->engine->env eq 'HASH' ){ |
24
|
0
|
|
|
|
|
|
$env = $c->engine->env; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
|
|
|
|
|
$env = \%ENV; |
28
|
|
|
|
|
|
|
} |
29
|
0
|
0
|
|
|
|
|
if( ref $name eq 'ARRAY'){ |
30
|
0
|
|
|
|
|
|
foreach ( @$name ){ |
31
|
0
|
|
|
|
|
|
$value = $get->($_,$env); |
32
|
0
|
0
|
|
|
|
|
if ( $value ) { last; } |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
|
$value = $get->($name,$env); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $value; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Catalyst::Plugin::ENV - getter for value from enviroment |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
In some tasks in catalyst app - you need value for your variable from %ENV |
54
|
|
|
|
|
|
|
When catapp works as fcgi server - you can get this values from $c->engine->env |
55
|
|
|
|
|
|
|
If you run devel catalyst server - you can get this values from %ENV |
56
|
|
|
|
|
|
|
The plugin give you availablity to get value from enviroment with one method C<get_env_value> |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 get_env_value |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Getter for value from environment |
63
|
|
|
|
|
|
|
Input param: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item c<name> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
If scalar - name to get value from environment |
68
|
|
|
|
|
|
|
If array ref - array ref to get value from environment |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
PLCGI C<plcgi1 (-) gmail.com> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 LICENSE |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify |
77
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|