File Coverage

blib/lib/Log/ger/Plugin/Multisets.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 4 50.0
condition 1 9 11.1
subroutine 6 6 100.0
pod 0 2 0.0
total 37 49 75.5


line stmt bran cond sub pod time code
1             package Log::ger::Plugin::Multisets;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-03-11'; # DATE
5             our $DIST = 'Log-ger-Plugin-Multisets'; # DIST
6             our $VERSION = '0.003'; # VERSION
7              
8 1     1   67658 use strict;
  1         11  
  1         36  
9 1     1   4 use warnings;
  1         2  
  1         19  
10              
11 1     1   4 use Log::ger ();
  1         1  
  1         242  
12              
13             sub meta { +{
14 1     1 0 14 v => 2,
15             } }
16              
17             sub get_hooks {
18 1     1 0 12 my %plugin_conf = @_;
19              
20             die "Please specify at least one of ".
21             "log_sub_prefixes|is_sub_prefixes|log_method_prefixes|is_method_prefixes"
22             unless
23             $plugin_conf{logger_sub_prefixes} ||
24             $plugin_conf{level_checker_sub_prefixes} ||
25             $plugin_conf{logger_method_prefixes} ||
26 1 0 33     3 $plugin_conf{level_checker_method_prefixes};
      0        
      0        
27              
28             return {
29             create_routine_names => [
30             __PACKAGE__, # key
31             50, # priority
32             sub { # hook
33 1     1   169 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
34              
35 1         3 my $levels = [keys %Log::ger::Levels];
36              
37 1         2 my $routine_names = {};
38 1         2 for my $key0 (qw(logger_sub level_checker_sub logger_method level_checker_method)) {
39 4         7 my $routine_names_key = "${key0}s";
40 4         5 my $plugin_conf_key = "${key0}_prefixes";
41 4         7 $routine_names->{$routine_names_key} = [];
42 4 100       10 next unless $plugin_conf{$plugin_conf_key};
43 2         3 for my $prefix (keys %{ $plugin_conf{$plugin_conf_key} }) {
  2         4  
44 4         5 my $init_args = $plugin_conf{$plugin_conf_key}{$prefix};
45 4         6 push @{ $routine_names->{$routine_names_key} }, map
46 4         4 { ["${prefix}$_", $_, undef, $init_args] }
  24         47  
47             @$levels;
48             }
49             }
50              
51 1         3 [$routine_names, 1];
52 1         7 }],
53             };
54             }
55              
56             1;
57             # ABSTRACT: Create multiple sets of logger routines, each set with its own init arguments
58              
59             __END__