line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::HasEnv; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
3
|
|
|
3
|
|
101046
|
$MooX::HasEnv::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$MooX::HasEnv::VERSION = '0.004'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: Making attributes based on ENV variables |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
28
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
139
|
|
11
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
97
|
|
12
|
3
|
|
|
3
|
|
2670
|
use Package::Stash; |
|
3
|
|
|
|
|
42034
|
|
|
3
|
|
|
|
|
707
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub import { |
15
|
3
|
|
|
3
|
|
25
|
my ( $class ) = @_; |
16
|
3
|
|
|
|
|
9
|
my $caller = caller; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
3195
|
eval qq{ |
|
3
|
|
|
|
|
47646
|
|
|
3
|
|
|
|
|
21
|
|
|
3
|
|
|
|
|
238
|
|
19
|
|
|
|
|
|
|
package $caller; |
20
|
|
|
|
|
|
|
use Moo; |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
6736
|
my $stash = Package::Stash->new($caller); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$stash->add_symbol('&has_env', sub { |
26
|
8
|
|
|
8
|
|
23648
|
my ( $name, $env_var, $default ) = @_; |
27
|
8
|
|
|
|
|
21
|
my $builder = '_build_'.$name; |
28
|
|
|
|
|
|
|
$stash->add_symbol('&'.$builder, sub { |
29
|
7
|
|
|
7
|
|
7364
|
my ( $self ) = @_; |
30
|
7
|
100
|
100
|
|
|
121
|
my $env_value = defined $env_var && defined $ENV{$env_var} ? $ENV{$env_var} : undef; |
31
|
7
|
100
|
|
|
|
61
|
return defined $env_value ? |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$env_value : |
33
|
|
|
|
|
|
|
defined $default ? |
34
|
|
|
|
|
|
|
ref $default eq 'CODE' ? |
35
|
|
|
|
|
|
|
$default->($self) : |
36
|
|
|
|
|
|
|
$default : |
37
|
|
|
|
|
|
|
undef; |
38
|
8
|
|
|
|
|
86
|
}); |
39
|
8
|
|
|
|
|
61
|
$caller->can("has")->($name, |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
lazy => 1, |
42
|
|
|
|
|
|
|
builder => $builder, |
43
|
|
|
|
|
|
|
); |
44
|
3
|
|
|
|
|
237
|
}); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |