File Coverage

blib/lib/Log/Log4perl/NDC/Scoped.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 4 75.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             package Log::Log4perl::NDC::Scoped;
2              
3             # Log4perl is compatible with perl 5.00503
4             # but through a source filter when installing
5             # We won't do that... :)
6              
7 2     2   144472 use 5.006;
  2         8  
  2         92  
8 2     2   13 use strict;
  2         5  
  2         82  
9 2     2   17 use warnings;
  2         9  
  2         70  
10 2     2   1576 use Log::Log4perl;
  2         191982  
  2         14  
11 2     2   110 use Carp qw(croak);
  2         2  
  2         148  
12 2     2   12 use base qw(Exporter);
  2         3  
  2         792  
13              
14             our $VERSION = '0.02';
15             our @EXPORT_OK = qw(push_ndc);
16             our %EXPORT_TAGS = (all => \@EXPORT_OK);
17             our $SEPARATOR = '|';
18              
19             sub _push {
20 4     4   12 my ($class, @parts) = @_;
21              
22 4 100       289 croak "NDC is useless in void context!" unless defined wantarray;
23              
24 3 50       6 my $str = join $SEPARATOR, map { defined $_ ? $_ : '' } @parts;
  5         20  
25 3         19 Log::Log4perl::NDC->push($str);
26              
27 3         41 return bless { ndc => $str }, $class;
28             }
29              
30             sub DESTROY {
31 3     3   2425 Log::Log4perl::NDC->pop();
32 3         170 return;
33             }
34              
35             sub push_ndc {
36 4     4 1 12314 return __PACKAGE__->_push(@_);
37             }
38              
39             1;
40              
41             __END__