| 1 | package Net::Async::Webservice::Common::WithConfigFile; | ||||||||||
| 2 | 1 | $Net::Async::Webservice::Common::WithConfigFile::VERSION = '1.0.2'; | |||||||||
| 3 | { | ||||||||||
| 4 | 1 | $Net::Async::Webservice::Common::WithConfigFile::DIST = 'Net-Async-Webservice-Common'; | |||||||||
| 5 | } | ||||||||||
| 6 | 1 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Net::Async::Webservice::Common::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # ABSTRACT: automatically load constructor args from a config file | ||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 15 | 1 | my ($orig,$class,@args) = @_; | |||||||||
| 16 | |||||||||||
| 17 | 1 | my $ret = $class->$orig(@args); | |||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | if (my $config_file = delete $ret->{config_file}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | $ret = { | ||||||||||
| 21 | 1 | %{_load_config_file($config_file)}, | |||||||||
| 22 | %$ret, | ||||||||||
| 23 | }; | ||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 1 | return $ret; | |||||||||
| 27 | 1 | }; | |||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | sub _load_config_file { | ||||||||
|
Subroutine
_load_config_file: called CC=2 SCAR=7.0
| |||||||||||
| 30 | 1 | my ($file) = @_; | |||||||||
| 31 | 1 | require Config::Any; | |||||||||
| 32 | 1 | my $loaded = Config::Any->load_files({ | |||||||||
| 33 | files => [$file], | ||||||||||
| 34 | use_ext => 1, | ||||||||||
| 35 | flatten_to_hash => 1, | ||||||||||
| 36 | }); | ||||||||||
| 37 | 1 | my $config = $loaded->{$file}; | |||||||||
| 38 | 1 | ▶ | Net::Async::Webservice::Common::Exception::ConfigError->throw({ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | file => $file, | ||||||||||
| 40 | }) unless $config; | ||||||||||
| 41 | 1 | return $config; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 1 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||