| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package JLogger::Config; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 487 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 243 | use YAML(); | 
|  | 1 |  |  |  |  | 4751 |  | 
|  | 1 |  |  |  |  | 70 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub new { | 
| 9 | 1 |  |  | 1 | 0 | 614 | bless {}, shift; | 
| 10 |  |  |  |  |  |  | } | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub load { | 
| 13 | 1 |  |  | 1 | 0 | 599 | my ($self, $config_text) = @_; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 |  |  |  |  | 3 | my $config = YAML::Load($config_text); | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1 |  |  |  |  | 21646 | $self->_fix_element($config, 'transport'); | 
| 18 | 1 |  |  |  |  | 8 | $self->_fix_elements($config, 'storages'); | 
| 19 | 1 |  |  |  |  | 7 | $self->_fix_elements_recursive($config, 'filters'); | 
| 20 | 1 |  |  | 1 |  | 372 | use Data::Dumper; warn Dumper $config; | 
|  | 1 |  |  |  |  | 4827 |  | 
|  | 1 |  |  |  |  | 326 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 1 |  |  |  |  | 268 | $config; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub load_file { | 
| 26 | 0 |  |  | 0 | 0 | 0 | my ($self, $config_file) = @_; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 0 | 0 |  |  |  | 0 | open my $fh, '<:encoding(UTF-8)', $config_file, | 
| 29 |  |  |  |  |  |  | or die qq(Can't open "$config_file": $!); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  | 0 | my $config_text = do { | 
| 32 | 0 |  |  |  |  | 0 | local $/; | 
| 33 | 0 |  |  |  |  | 0 | <$fh>; | 
| 34 |  |  |  |  |  |  | }; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 |  |  |  |  | 0 | close $fh; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 0 |  |  |  |  | 0 | $self->load($config_text); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub _fix_element { | 
| 42 | 1 |  |  | 1 |  | 5 | my ($self, $config, $element_key) = @_; | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | $config->{$element_key} = | 
| 45 |  |  |  |  |  |  | $self->_fix_element_value($config->{$element_key}) | 
| 46 | 1 | 50 |  |  |  | 12 | if exists $config->{$element_key}; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub _fix_elements { | 
| 50 | 5 |  |  | 5 |  | 18 | my ($self, $config, $elements_key) = @_; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 5 | 100 |  |  |  | 17 | if (exists $config->{$elements_key}) { | 
| 53 | 2 |  |  |  |  | 4 | $_ = $self->_fix_element_value($_) for @{$config->{$elements_key}}; | 
|  | 2 |  |  |  |  | 11 |  | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub _fix_elements_recursive { | 
| 58 | 16 |  |  | 16 |  | 36 | my ($self, $config, $elements_key) = @_; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 16 |  |  |  |  | 38 | my $ref = ref $config; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 16 | 100 |  |  |  | 59 | if ($ref eq 'HASH') { | 
|  |  | 100 |  |  |  |  |  | 
| 63 | 4 |  |  |  |  | 14 | $self->_fix_elements($config, $elements_key); | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 4 |  |  |  |  | 15 | foreach my $child (values %$config) { | 
| 66 | 8 |  |  |  |  | 30 | $self->_fix_elements_recursive($child, $elements_key); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | } elsif ($ref eq 'ARRAY') { | 
| 69 | 5 |  |  |  |  | 13 | foreach my $child (@$config) { | 
| 70 | 7 |  |  |  |  | 23 | $self->_fix_elements_recursive($child, $elements_key); | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub _fix_element_value { | 
| 76 | 3 |  |  | 3 |  | 12 | my ($self, $element) = @_; | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 3 |  |  |  |  | 9 | my $ref = ref $element; | 
| 79 | 3 | 100 |  |  |  | 16 | if ($ref eq '') { | 
|  |  | 50 |  |  |  |  |  | 
| 80 | 1 |  |  |  |  | 6 | return [$element]; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  | elsif ($ref eq 'HASH') { | 
| 83 | 2 |  |  |  |  | 14 | return [%$element]; | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 0 |  |  |  |  |  | $element; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | 1; |