File Coverage

lib/Log/Message/Item.pm
Criterion Covered Total %
statement 46 46 100.0
branch 3 4 75.0
condition n/a
subroutine 14 14 100.0
pod 1 2 50.0
total 64 66 96.9


line stmt bran cond sub pod time code
1             package Log::Message::Item;
2 2     2   12 use if $] > 5.017, 'deprecate';
  2         5  
  2         18  
3              
4 2     2   415 use strict;
  2         3  
  2         81  
5 2     2   16 use vars qw[$VERSION];
  2         3  
  2         102  
6 2     2   11 use Params::Check qw[check];
  2         3  
  2         89  
7 2     2   2602 use Log::Message::Handlers;
  2         6  
  2         68  
8              
9             ### for the messages to store ###
10 2     2   13 use Carp ();
  2         5  
  2         147  
11              
12             BEGIN {
13 2     2   11 use vars qw[$AUTOLOAD $VERSION];
  2         2  
  2         100  
14              
15 2     2   807 $VERSION = '0.08';
16             }
17              
18             ### create a new item.
19             ### note that only an id (position on the stack), message and a reference
20             ### to its parent are required. all the other things it can fill in itself
21             sub new {
22 5     5 0 6 my $class = shift;
23 5         20 my %hash = @_;
24              
25 5         1188 my $tmpl = {
26             when => { no_override => 1, default => scalar localtime },
27             id => { required => 1 },
28             message => { required => 1 },
29             parent => { required => 1 },
30             level => { default => '' }, # default may be conf dependant
31             tag => { default => '' }, # default may be conf dependant
32             longmess => { default => _clean(Carp::longmess()) },
33             shortmess => { default => _clean(Carp::shortmess())},
34             };
35              
36 5 50       90 my $args = check($tmpl, \%hash) or return undef;
37              
38 5         933 return bless $args, $class;
39             }
40              
41 10     10   868 sub _clean { map { s/\s*//; chomp; $_ } shift; }
  10         44  
  10         21  
  10         779  
42              
43             sub remove {
44 1     1 1 5408 my $item = shift;
45 1         135 my $self = $item->parent;
46              
47 1         3 return splice( @{$self->{STACK}}, $item->id, 1, undef );
  1         7  
48             }
49              
50             sub AUTOLOAD {
51 123     123   1994 my $self = $_[0];
52              
53 123         528 $AUTOLOAD =~ s/.+:://;
54              
55 123 100       1041 return $self->{$AUTOLOAD} if exists $self->{$AUTOLOAD};
56              
57 7         13 local $Carp::CarpLevel = $Carp::CarpLevel + 3;
58              
59 2     2   12 { no strict 'refs';
  2         5  
  2         214  
  7         9  
60 7         10 return *{"Log::Message::Handlers::${AUTOLOAD}"}->(@_);
  7         42  
61             }
62             }
63              
64 5     5   471 sub DESTROY { 1 }
65              
66             1;
67              
68             __END__