File Coverage

blib/lib/Log/ger/Plugin.pm
Criterion Covered Total %
statement 32 34 94.1
branch 6 8 75.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 0 2 0.0
total 47 55 85.4


line stmt bran cond sub pod time code
1             package Log::ger::Plugin;
2              
3 13     13   414284 use strict;
  13         31  
  13         592  
4 13     13   76 use warnings;
  13         33  
  13         951  
5              
6 13     13   5346 use Log::ger::Util;
  13         34  
  13         6567  
7              
8             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9             our $DATE = '2023-12-29'; # DATE
10             our $DIST = 'Log-ger'; # DIST
11             our $VERSION = '0.042'; # VERSION
12              
13             sub set {
14 18     18 0 444815 my $pkg = shift;
15              
16 18         35 my %args;
17 18 100       66 if (ref $_[0] eq 'HASH') {
18 2         2 %args = %{shift()};
  2         9  
19             } else {
20 16         80 %args = (name => shift, conf => {@_});
21             }
22              
23 18   33     179 $args{prefix} ||= $pkg . '::';
24 18         60 $args{replace_package_regex} = $pkg->_replace_package_regex;
25 18         113 Log::ger::Util::set_plugin(%args);
26             }
27              
28             sub set_for_current_package {
29 2     2 0 5 my $pkg = shift;
30              
31 2         14 my %args;
32 2 50       9 if (ref $_[0] eq 'HASH') {
33 0         0 %args = %{shift()};
  0         0  
34             } else {
35 2         8 %args = (name => shift, conf => {@_});
36             }
37              
38 2         5 my $caller = caller(0);
39 2         4 $args{target} = 'package';
40 2         4 $args{target_arg} = $caller;
41              
42 2         6 set($pkg, \%args);
43             }
44              
45 1     1   9 sub _import_sets_for_current_package { 0 }
46              
47 2     2   36 sub _replace_package_regex { undef }
48              
49             sub import {
50 3 50   3   36 if (@_ > 1) {
51 3 100       11 if ($_[0]->_import_sets_for_current_package) {
52 2         6 goto &set_for_current_package;
53             } else {
54 1         3 goto &set;
55             }
56             }
57             }
58              
59             1;
60             # ABSTRACT: Use a plugin
61              
62             __END__