File Coverage

blib/lib/XML/Stream/Tools.pm
Criterion Covered Total %
statement 22 38 57.8
branch 8 16 50.0
condition 3 4 75.0
subroutine 4 4 100.0
pod 0 1 0.0
total 37 63 58.7


line stmt bran cond sub pod time code
1             package XML::Stream::Tools;
2 11     11   73 use strict;
  11         22  
  11         387  
3 11     11   60 use warnings;
  11         21  
  11         266  
4              
5 11     11   63 use FileHandle;
  11         20  
  11         101  
6              
7             # helper function (not a method!)
8             sub setup_debug {
9 18     18 0 76 my ($self, %args) = @_;
10              
11 18         47 $self->{DEBUGTIME} = 0;
12 18 100       75 $self->{DEBUGTIME} = $args{debugtime} if exists($args{debugtime});
13              
14 18         55 $self->{DEBUGLEVEL} = 0;
15 18 100       63 $self->{DEBUGLEVEL} = $args{debuglevel} if exists($args{debuglevel});
16              
17 18         50 $self->{DEBUGFILE} = "";
18              
19 18   50     108 $args{debugfh} ||= '';
20 18   100     102 $args{debug} ||= '';
21              
22 18 50       142 if ($args{debugfh} ne "")
    100          
23             {
24 0         0 $self->{DEBUGFILE} = $args{debugfh};
25 0         0 $self->{DEBUG} = 1;
26             }
27             elsif ($args{debug} ne "")
28             {
29 2         6 $self->{DEBUG} = 1;
30 2 50       8 if (lc($args{debug}) eq "stdout")
31             {
32 2         20 $self->{DEBUGFILE} = FileHandle->new(">&STDERR");
33 2         172 $self->{DEBUGFILE}->autoflush(1);
34             }
35             else
36             {
37 0 0         if (-e $args{debug})
38             {
39 0 0         if (-w $args{debug})
40             {
41 0           $self->{DEBUGFILE} = FileHandle->new(">$args{debug}");
42 0           $self->{DEBUGFILE}->autoflush(1);
43             }
44             else
45             {
46 0           print "WARNING: debug file ($args{debug}) is not writable by you\n";
47 0           print " No debug information being saved.\n";
48 0           $self->{DEBUG} = 0;
49             }
50             }
51             else
52             {
53 0           $self->{DEBUGFILE} = FileHandle->new(">$args{debug}");
54 0 0         if (defined($self->{DEBUGFILE}))
55             {
56 0           $self->{DEBUGFILE}->autoflush(1);
57             }
58             else
59             {
60 0           print "WARNING: debug file ($args{debug}) does not exist \n";
61 0           print " and is not writable by you.\n";
62 0           print " No debug information being saved.\n";
63 0           $self->{DEBUG} = 0;
64             }
65             }
66             }
67             }
68             }
69              
70              
71              
72              
73             1;
74              
75