File Coverage

blib/lib/Puppet/LogBody.pm
Criterion Covered Total %
statement 36 36 100.0
branch 8 10 80.0
condition n/a
subroutine 7 7 100.0
pod 4 4 100.0
total 55 57 96.4


line stmt bran cond sub pod time code
1             ############################################################
2             #
3             # $Header: /home/domi/perlDev/old/Puppet_LogBody/RCS/LogBody.pm,v 1.3 2007/09/20 12:55:03 domi Exp $
4             #
5             # $Source: /home/domi/perlDev/old/Puppet_LogBody/RCS/LogBody.pm,v $
6             # $Revision: 1.3 $
7             # $Locker: $
8             #
9             ############################################################
10              
11             package Puppet::LogBody ;
12              
13 1     1   6505 use Carp ;
  1         3  
  1         209  
14              
15 1     1   6 use strict ;
  1         2  
  1         49  
16 1     1   6 use vars qw($VERSION) ;
  1         6  
  1         404  
17              
18             $VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/;
19              
20             # see loadspecs for other names
21             sub new
22             {
23 1     1 1 150 my $type = shift ;
24 1         4 my $self = {} ;
25 1         6 my %args = @_ ;
26              
27 1         4 $self->{name} = $args{'name'} ; #complete log name
28              
29 1         4 $self->{how} = $args{'how'} ;
30              
31 1         18 $self->{'data'}= [] ;
32              
33 1         7 bless $self,$type ;
34             }
35              
36             sub log
37             {
38 5     5 1 324 my $self = shift ;
39 5         12 my $text = shift ;
40 5         13 my %args = @_ ;
41              
42 5 100       29 my $how = exists $args{'how'} ? $args{how} : $self->{how};
43              
44 5         11 chomp ($text) ;
45 5         7 $text .= "\n";
46              
47 5         7 push @{$self->{'data'}}, $text ; # always keep text in local array
  5         13  
48              
49 5 100       32 if (defined $how)
50             {
51 3 50       13 my $str = defined $self->{name} ? $self->{name}.": \n\t" : '';
52 3         4 $str .= $text;
53 3 100       11 if ($how eq 'print') {print $str ;}
  2 50       28  
  1         26  
54             elsif ($how eq 'warn') {warn $str ;}
55             }
56 5         17 return $text ;
57             }
58              
59             sub clear
60             {
61 1     1 1 25 my $self = shift ;
62 1         5 $self->{'data'} =[];
63             }
64              
65             sub getAll
66             {
67 2     2 1 254 my $self = shift ;
68 2         6 return @{$self->{'data'}} ;
  2         105  
69             }
70              
71             1;
72              
73             __END__