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 1     1   64926 use strict;
  1         15  
  1         24  
4 1     1   4 use warnings;
  1         3  
  1         19  
5              
6 1     1   4 use Log::ger ();
  1         2  
  1         292  
7              
8             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9             our $DATE = '2022-05-16'; # DATE
10             our $DIST = 'Log-ger-Plugin-Multisets'; # DIST
11             our $VERSION = '0.005'; # VERSION
12              
13             sub meta { +{
14 1     1 0 13 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             "logger_sub_prefixes|level_checker_sub_prefixes|logger_method_prefixes|level_checker_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     4 $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   171 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
34              
35 1         4 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         9 my $routine_names_key = "${key0}s";
40 4         6 my $plugin_conf_key = "${key0}_prefixes";
41 4         13 $routine_names->{$routine_names_key} = [];
42 4 100       11 next unless $plugin_conf{$plugin_conf_key};
43 2         2 for my $prefix (keys %{ $plugin_conf{$plugin_conf_key} }) {
  2         5  
44 4         7 my $init_args = $plugin_conf{$plugin_conf_key}{$prefix};
45 4         7 push @{ $routine_names->{$routine_names_key} }, map
46 4         5 { ["${prefix}$_", $_, undef, $init_args] }
  24         58  
47             @$levels;
48             }
49             }
50              
51 1         5 [$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__