opentick/Output.pm

filter: Statementstmt 100% 77 / 77 Branchbran 62.5% 20 / 32 Conditioncond 40.0% 12 / 30 MC/DCmcdc 5.0% 1 / 20 Subroutinesub 100% 22 / 22 Podpod 100% 14 / 14 totaltotal 74.8% 146 / 195 CC 27 SCAR 11.5
CC
27
Cov
78%
set_debug
5.0
set_quiet
5.0
set_prefix
5.0
CRAP 3.1
« opentick/Record.pm ↑ Summary opentick/Error.pm »
1 package POE::Component::Client::opentick::Output;
2 #
3 # opentick.com POE client
4 #
5 # Diagnostic message output class
6 #
7 # infi/2008
8 #
9 # $Id: Output.pm 56 2009-01-08 16:51:14Z infidel $
10 #
11 # Full POD documentation after __END__
12 #
13  
14 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use overload '""' => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶use vars qw( $VERSION $TRUE $FALSE $DEBUG $QUIET $PREFIX );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 require Exporter;
24 4 our @ISA = qw( Exporter );
25 4 our @EXPORT = qw( O_DEBUG O_INFO O_NOTICE O_WARN O_ERROR );
26 4 ($VERSION) = q$Revision: 56 $ =~ /(\d+)/;
27 }
28  
29 ###
30 ### Variables
31 ###
32  
33 4 *TRUE = \1;
34 4 *FALSE = \0;
35 4 $DEBUG = $FALSE;
36 4 $QUIET = $FALSE;
37 4 $PREFIX = $TRUE;
38  
39 4 my $output = {
40 DEBUG => *STDERR,
41 INFO => *STDOUT,
42 NOTICE => *STDOUT,
43 WARN => *STDERR,
44 ERROR => *STDERR,
45 };
46  
47 ###
48 ### Exported functions
49 ###
50  
51 sub O_DEBUG
52 24 ▶{
Subroutine O_DEBUG: called CC=4 SCAR=14.5
Pod documented
53 24 my @msg = @_;
54 24 my $msg = join( ' ', @msg );
55  
56 24 ▶ _output( $msg, 'DEBUG' ) if $DEBUG and( !defined( wantarray ) );
Branch: 1 branch
BranchTrueFalseTotal
if $POE::Component::Client::opentick::Output::DEBUG and not defined wantarray 1 23 24
Condition66%2/3
$POE::Component::Client::opentick::Output::DEBUG and not defined wantarray
!ll&&!rl&&r
2301
MC/DC50%1/2
$POE::Component::Client::opentick::Output::DEBUG and not defined wantarray
$POE::Component::Client::opentick::Output::DEBUG not defined wantarray
Truth table66%2/3
A and not(B)
A= $POE::Component::Client::opentick::Output::DEBUGB= not defined wantarray
ABresult
0X0
100
111
57  
58 return( defined( wantarray )
59 24 ▶ and POE::Component::Client::opentick::Output->new( 'DEBUG', $msg ) );
Condition33%1/3
defined wantarray && 'POE::Component::Client::opentick::Output'->new('DEBUG', $msg)
!ll&&!rl&&r
2400
MC/DC0%0/2
defined wantarray && 'POE::Component::Client::opentick::Output'->new('DEBUG', $msg)
defined wantarray 'POE::Component::Client::opentick::Output'->new('DEBUG', $msg)
Truth table33%1/3
A && B
A= defined wantarrayB= 'POE::Component::Client::opentick::Output'->new('DEBUG', $msg)
ABresult
0X0
100
111
60 }
61  
62 sub O_INFO
63 2 ▶{
Subroutine O_INFO: called CC=3 SCAR=12.0
Pod documented
64 2 my @msg = @_;
65 2 my $msg = join( ' ', @msg );
66  
67 2 ▶ _output( $msg, 'INFO' ) unless( defined( wantarray ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 2 0 2
68  
69 return( defined( wantarray )
70 2 ▶ and POE::Component::Client::opentick::Output->new( 'INFO', $msg ) );
Condition33%1/3
defined wantarray && 'POE::Component::Client::opentick::Output'->new('INFO', $msg)
!ll&&!rl&&r
200
MC/DC0%0/2
defined wantarray && 'POE::Component::Client::opentick::Output'->new('INFO', $msg)
defined wantarray 'POE::Component::Client::opentick::Output'->new('INFO', $msg)
Truth table33%1/3
A && B
A= defined wantarrayB= 'POE::Component::Client::opentick::Output'->new('INFO', $msg)
ABresult
0X0
100
111
71 }
72  
73 sub O_NOTICE
74 6 ▶{
Subroutine O_NOTICE: called CC=3 SCAR=12.0
Pod documented
75 6 my @msg = @_;
76 6 my $msg = join( ' ', @msg );
77  
78 6 ▶ _output( $msg, 'NOTICE' ) unless( defined( wantarray ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 6 0 6
79  
80 return( defined( wantarray )
81 6 ▶ and POE::Component::Client::opentick::Output->new( 'NOTICE', $msg ) );
Condition33%1/3
defined wantarray && 'POE::Component::Client::opentick::Output'->new('NOTICE', $msg)
!ll&&!rl&&r
600
MC/DC0%0/2
defined wantarray && 'POE::Component::Client::opentick::Output'->new('NOTICE', $msg)
defined wantarray 'POE::Component::Client::opentick::Output'->new('NOTICE', $msg)
Truth table33%1/3
A && B
A= defined wantarrayB= 'POE::Component::Client::opentick::Output'->new('NOTICE', $msg)
ABresult
0X0
100
111
82 }
83  
84 sub O_WARN
85 3 ▶{
Subroutine O_WARN: called CC=3 SCAR=12.0
Pod documented
86 3 my @msg = @_;
87 3 my $msg = join( ' ', @msg );
88  
89 3 ▶ _output( $msg, 'WARN' ) unless( defined( wantarray ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 3 0 3
90  
91 return( defined( wantarray )
92 3 ▶ and POE::Component::Client::opentick::Output->new( 'WARN', $msg ) );
Condition33%1/3
defined wantarray && 'POE::Component::Client::opentick::Output'->new('WARN', $msg)
!ll&&!rl&&r
300
MC/DC0%0/2
defined wantarray && 'POE::Component::Client::opentick::Output'->new('WARN', $msg)
defined wantarray 'POE::Component::Client::opentick::Output'->new('WARN', $msg)
Truth table33%1/3
A && B
A= defined wantarrayB= 'POE::Component::Client::opentick::Output'->new('WARN', $msg)
ABresult
0X0
100
111
93 }
94  
95 sub O_ERROR
96 2 ▶{
Subroutine O_ERROR: called CC=3 SCAR=11.0
Pod documented
97 2 my @msg = @_;
98 2 my $msg = join( ' ', @msg );
99  
100 2 ▶ _output( $msg, 'ERROR' ) unless( defined( wantarray ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 1 1 2
101  
102 return( defined( wantarray )
103 2 ▶ and POE::Component::Client::opentick::Output->new( 'ERROR', $msg ) );
Condition66%2/3
defined wantarray && 'POE::Component::Client::opentick::Output'->new('ERROR', $msg)
!ll&&!rl&&r
101
MC/DC0%0/2
defined wantarray && 'POE::Component::Client::opentick::Output'->new('ERROR', $msg)
defined wantarray 'POE::Component::Client::opentick::Output'->new('ERROR', $msg)
Truth table33%1/3
A && B
A= defined wantarrayB= 'POE::Component::Client::opentick::Output'->new('ERROR', $msg)
ABresult
0X0
100
111
104 }
105  
106 ###
107 ### Class methods
108 ###
109  
110 # Constructor
111 sub new
112 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
113 1 my( $class, $level, $msg, @args ) = @_;
114  
115 1 my $self = bless( {
116 level => $level,
117 message => $msg,
118 timestamp => time,
119 }, 'POE::Component::Client::opentick::Output' );
120  
121 1 $self->initialize( @args );
122  
123 1 return( $self );
124 }
125  
126 # Overload this.
127 1 ▶sub initialize {}
Subroutine initialize: called CC=1 SCAR=0.0
Pod documented
128  
129 # And this.
130 sub stringify
131 1 ▶{
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
132 1 my( $self ) = @_;
133  
134 1 my $message = sprintf( "OT:%s:%s:%s\n",
135 $self->get_level(),
136 $self->get_timestamp(),
137 $self->get_message() );
138  
139 1 return( $message );
140 }
141  
142 ###
143 ### Accessor methods
144 ###
145  
146 # Hybrid method; set the DEBUG flag
147 sub set_debug
148 1 ▶{
Subroutine set_debug: called CC=4 SCAR=16.1
Pod documented
149 1 my $junk = shift;
150 1 ▶ my $value = ref( $junk ) || $junk =~ /::/ ? shift : $junk;
Branch: 1 branch
BranchTrueFalseTotal
ref $junk || $junk =~ /::/ ? : 1 0 1
Condition33%1/3
ref $junk or $junk =~ /::/
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $junk or $junk =~ /::/
ref $junk $junk =~ /::/
Truth table33%1/3
A or B
A= ref $junkB= $junk =~ /::/
ABresult
1X1
011
000
151  
152 1 ▶ return( $DEBUG = $value ? $TRUE : $FALSE );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 0 1
153 }
154  
155 # Hybrid method: set the QUIET flag; overrides DEBUG
156 sub set_quiet
157 2 ▶{
Subroutine set_quiet: called CC=4 SCAR=16.1
Pod documented
158 2 my( $junk ) = shift;
159 2 ▶ my $value = ref( $junk ) || $junk =~ /::/ ? shift : $junk;
Branch: 1 branch
BranchTrueFalseTotal
ref $junk || $junk =~ /::/ ? : 2 0 2
Condition33%1/3
ref $junk or $junk =~ /::/
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $junk or $junk =~ /::/
ref $junk $junk =~ /::/
Truth table33%1/3
A or B
A= ref $junkB= $junk =~ /::/
ABresult
1X1
011
000
160  
161 2 ▶ return( $QUIET = $value ? $TRUE : $FALSE );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 2 0 2
162 }
163  
164 # Hybrid method: set the PREFIX flag.
165 sub set_prefix
166 1 ▶{
Subroutine set_prefix: called CC=4 SCAR=16.1
Pod documented
167 1 my $junk = shift;
168 1 ▶ my $value = ref( $junk ) || $junk =~ /::/ ? shift : $junk;
Branch: 1 branch
BranchTrueFalseTotal
ref $junk || $junk =~ /::/ ? : 1 0 1
Condition33%1/3
ref $junk or $junk =~ /::/
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $junk or $junk =~ /::/
ref $junk $junk =~ /::/
Truth table33%1/3
A or B
A= ref $junkB= $junk =~ /::/
ABresult
1X1
011
000
169  
170 1 ▶ return( $PREFIX = $value ? $TRUE : $FALSE );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 1 1
171 }
172  
173 # INSTANCE METHOD
174 sub get_level
175 2 ▶{
Subroutine get_level: called CC=2 SCAR=7.1
Pod documented
176 2 my( $self ) = shift;
177 2 ▶ return unless( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 2 2
178  
179 2 return( $self->{level} );
180 }
181  
182 # INSTANCE METHOD
183 sub get_message
184 2 ▶{
Subroutine get_message: called CC=2 SCAR=7.1
Pod documented
185 2 my( $self ) = shift;
186 2 ▶ return unless( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 2 2
187  
188 2 return( $self->{message} );
189 }
190  
191 # INSTANCE METHOD
192 sub get_timestamp
193 2 ▶{
Subroutine get_timestamp: called CC=2 SCAR=7.1
Pod documented
194 2 my( $self ) = shift;
195 2 ▶ return unless( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 2 2
196  
197 2 return( $self->{timestamp} );
198 }
199  
200 ###
201 ### Private methods
202 ###
203  
204 # Private output method
205 sub _output
206 13 ▶{
Subroutine _output: called CC=3 SCAR=11.0
207 13 ▶ return if $QUIET;
Branch: 1 branch
BranchTrueFalseTotal
if $POE::Component::Client::opentick::Output::QUIET 6 7 13
208 7 my( $msg, $level ) = @_;
209  
210 7 ▶ printf { _get_filehandle( $level ) } "%s%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$POE::Component::Client::opentick::Output::PREFIX ? : 6 1 7
211 $PREFIX
212 ? 'OT:' . $level . ': '
213 : '',
214 $msg;
215 }
216  
217 sub _get_filehandle
218 7 ▶{
Subroutine _get_filehandle: called CC=2 SCAR=8.1
219 7 my( $level ) = @_;
220  
221 7 ▶ return( $output->{$level} || *STDOUT );
Condition33%1/3
$output->{$level} || *STDOUT
l!l&&r!l&&!r
700
MC/DC0%0/2
$output->{$level} || *STDOUT
$output->{$level} *STDOUT
Truth table33%1/3
A || B
A= $output->{$level}B= *STDOUT
ABresult
1X1
011
000
222 }
223  
224 4 1;
225  
226 __END__
« opentick/Record.pm ↑ Summary opentick/Error.pm »