File Coverage

lib/Class/STL/Trace.pm
Criterion Covered Total %
statement 57 91 62.6
branch 12 34 35.2
condition 2 10 20.0
subroutine 15 21 71.4
pod 0 11 0.0
total 86 167 51.5


line stmt bran cond sub pod time code
1             # vim:ts=4 sw=4
2             # ----------------------------------------------------------------------------------------------------
3             # Name : Class::STL::Trace.pm
4             # Created : 12 May 2006
5             # Author : Mario Gaffiero (gaffie)
6             #
7             # Copyright 2006-2007 Mario Gaffiero.
8             #
9             # This file is part of Class::STL::Containers(TM).
10             #
11             # Class::STL::Containers is free software; you can redistribute it and/or modify
12             # it under the terms of the GNU General Public License as published by
13             # the Free Software Foundation; version 2 of the License.
14             #
15             # Class::STL::Containers is distributed in the hope that it will be useful,
16             # but WITHOUT ANY WARRANTY; without even the implied warranty of
17             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18             # GNU General Public License for more details.
19             #
20             # You should have received a copy of the GNU General Public License
21             # along with Class::STL::Containers; if not, write to the Free Software
22             # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23             # ----------------------------------------------------------------------------------------------------
24             # Modification History
25             # When Version Who What
26             # ----------------------------------------------------------------------------------------------------
27             # TO DO:
28             # ----------------------------------------------------------------------------------------------------
29             package Class::STL::Trace;
30             require 5.005_62;
31 7     7   40 use strict;
  7         12  
  7         205  
32 7     7   29 use warnings;
  7         12  
  7         181  
33 7     7   37 use vars qw($VERSION $BUILD);
  7         16  
  7         396  
34             $VERSION = '0.25';
35             # ----------------------------------------------------------------------------------------------------
36             {
37             package Class::STL::Trace; # Singleton
38 7     7   35 use UNIVERSAL;
  7         11  
  7         22  
39 7     7   199 use Carp qw(confess);
  7         12  
  7         506  
40             sub new {
41 357     357 0 484 our $__class_stl_trace;
42 357 100       4061 return $__class_stl_trace if (defined($__class_stl_trace));
43 7     7   39 use vars qw(@ISA);
  7         10  
  7         2410  
44 7         12 my $proto = shift;
45 7   33     37 my $class = ref($proto) || $proto;
46 7 50       30 $__class_stl_trace = int(@ISA) ? $class->SUPER::new(@_) : {};
47 7         25 bless($__class_stl_trace, $class);
48 7         24 $__class_stl_trace->members_init(@_);
49 7         25 return $__class_stl_trace;
50             }
51             sub filename {
52 7     7 0 12 my $self = shift;
53 7 50       36 $self->{Class_STL_Trace}->{FILENAME} = shift if (@_);
54 7         13 return $self->{Class_STL_Trace}->{FILENAME};
55             }
56             sub trace_level {
57 7     7 0 15 my $self = shift;
58 7 50       33 $self->{Class_STL_Trace}->{TRACE_LEVEL} = shift if (@_);
59 7         14 return $self->{Class_STL_Trace}->{TRACE_LEVEL};
60             }
61             sub debug_on {
62 364     364 0 529 my $self = shift;
63 364 100       655 $self->{Class_STL_Trace}->{DEBUG_ON} = shift if (@_);
64 364         925 return $self->{Class_STL_Trace}->{DEBUG_ON};
65             }
66             sub print {
67 0     0 0 0 my $self = shift;
68 0   0     0 my $caller = shift || '';
69 0         0 open(DEBUG, ">>@{[ $self->filename() ]}");
  0         0  
70 0         0 print DEBUG "# $caller\n"; # !!! need to get this as arg to print !!!
71 0         0 print DEBUG @_, "\n";
72 0         0 close(DEBUG);
73             }
74             sub members_init {
75 7     7 0 13 my $self = shift;
76 7     7   48 use vars qw(@ISA);
  7         10  
  7         2161  
77 7 50 33     25 if (int(@ISA) && (caller())[0] ne __PACKAGE__) {
78 0         0 $self->SUPER::members_init(@_);
79             }
80 7         11 my @p;
81 7 50       21 while (@_) { my $p=shift; push(@p, $p, shift) if (!ref($p)); }
  7         10  
  7         30  
82 7         20 my %p = @p;
83 7 50       82 $self->filename(exists($p{'filename'}) ? $p{'filename'} : "class_stl_dump$$");
84 7 50       77 $self->trace_level(exists($p{'trace_level'}) ? $p{'trace_level'} : '0');
85 7 50       24 $self->debug_on(exists($p{'debug_on'}) ? $p{'debug_on'} : '0');
86             }
87             sub member_print {
88 0     0 0   my $self = shift;
89 0   0       my $delim = shift || '|';
90 0           return join("$delim",
91 0 0         "debug_on=@{[ defined($self->debug_on()) ? $self->debug_on() : 'NULL' ]}",
92 0 0         "filename=@{[ defined($self->filename()) ? $self->filename() : 'NULL' ]}",
93 0 0         "trace_level=@{[ defined($self->trace_level()) ? $self->trace_level() : 'NULL' ]}",
94             );
95             }
96             sub members_local { # static function
97             return {
98 0     0 0   debug_on=>[ '0', '' ],
99             filename=>[ "class_stl_dump$$", '' ],
100             trace_level=>[ '0', '' ],
101             };
102             }
103             sub members {
104 0     0 0   my $self = shift;
105 7     7   41 use vars qw(@ISA);
  7         14  
  7         851  
106 0 0         my $super = (int(@ISA)) ? $self->SUPER::members() : {};
107 0 0         return keys(%$super)
108             ? {
109             %$super,
110             debug_on=>[ '0', '' ],
111             filename=>[ "class_stl_dump$$", '' ],
112             trace_level=>[ '0', '' ]
113             }
114             : {
115             debug_on=>[ '0', '' ],
116             filename=>[ "class_stl_dump$$", '' ],
117             trace_level=>[ '0', '' ]
118             };
119             }
120             sub swap {
121 0     0 0   my $self = shift;
122 0           my $other = shift;
123 7     7   41 use vars qw(@ISA);
  7         10  
  7         12917  
124 0           my $tmp = $self->clone();
125 0 0         $self->SUPER::swap($other) if (int(@ISA));
126 0           $self->filename($other->filename());
127 0           $self->trace_level($other->trace_level());
128 0           $self->debug_on($other->debug_on());
129 0           $other->filename($tmp->filename());
130 0           $other->trace_level($tmp->trace_level());
131 0           $other->debug_on($tmp->debug_on());
132             }
133             sub clone {
134 0     0 0   my $self = shift;
135 7     7   59 use vars qw(@ISA);
  7         15  
  7         683  
136 0 0         my $clone = int(@ISA) ? $self->SUPER::clone() : $self->new();
137 0           $clone->filename($self->filename());
138 0           $clone->trace_level($self->trace_level());
139 0           $clone->debug_on($self->debug_on());
140 0           return $clone;
141             }
142             }
143             1;