line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Async::Webservice::Common::WithConfigFile; |
2
|
|
|
|
|
|
|
$Net::Async::Webservice::Common::WithConfigFile::VERSION = '1.0.2'; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$Net::Async::Webservice::Common::WithConfigFile::DIST = 'Net-Async-Webservice-Common'; |
5
|
|
|
|
|
|
|
} |
6
|
1
|
|
|
1
|
|
15426
|
use Moo::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
7
|
1
|
|
|
1
|
|
7050
|
use Net::Async::Webservice::Common::Exception; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
48
|
|
8
|
1
|
|
|
1
|
|
1032
|
use namespace::autoclean; |
|
1
|
|
|
|
|
15725
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
104
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
300
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: automatically load constructor args from a config file |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
around BUILDARGS => sub { |
15
|
|
|
|
|
|
|
my ($orig,$class,@args) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $ret = $class->$orig(@args); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if (my $config_file = delete $ret->{config_file}) { |
20
|
|
|
|
|
|
|
$ret = { |
21
|
|
|
|
|
|
|
%{_load_config_file($config_file)}, |
22
|
|
|
|
|
|
|
%$ret, |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return $ret; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _load_config_file { |
30
|
1
|
|
|
1
|
|
2
|
my ($file) = @_; |
31
|
1
|
|
|
|
|
255273
|
require Config::Any; |
32
|
1
|
|
|
|
|
348895
|
my $loaded = Config::Any->load_files({ |
33
|
|
|
|
|
|
|
files => [$file], |
34
|
|
|
|
|
|
|
use_ext => 1, |
35
|
|
|
|
|
|
|
flatten_to_hash => 1, |
36
|
|
|
|
|
|
|
}); |
37
|
1
|
|
|
|
|
1860546
|
my $config = $loaded->{$file}; |
38
|
1
|
50
|
|
|
|
9
|
Net::Async::Webservice::Common::Exception::ConfigError->throw({ |
39
|
|
|
|
|
|
|
file => $file, |
40
|
|
|
|
|
|
|
}) unless $config; |
41
|
1
|
|
|
|
|
7
|
return $config; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=encoding UTF-8 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Net::Async::Webservice::Common::WithConfigFile - automatically load constructor args from a config file |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 VERSION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
version 1.0.2 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package My::WS::Client { |
63
|
|
|
|
|
|
|
use Moo; |
64
|
|
|
|
|
|
|
with 'Net::Async::Webservice::Common::WithConfigFile'; |
65
|
|
|
|
|
|
|
has param => (is => 'ro', required => 1); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $c = My::WS::Client->new({config_file=>'/etc/my.conf'}); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This role wraps C<BUILDARGS> and, if a C<config_file> argument was |
73
|
|
|
|
|
|
|
passed to the constructor, loads that file with L<Config::Any> and |
74
|
|
|
|
|
|
|
adds the values loaded to the arguments (explicitly passed constructor |
75
|
|
|
|
|
|
|
arguments still take precedence). |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L<MooX::ConfigFromFile> for a more comprehensive solution. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Net-a-porter.com. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
90
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |