blib/lib/Pipeline/Base.pm

filter: Statementstmt 100% 38 / 38 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 98.3% 60 / 61 CC 5 SCAR 5.4
CC
5
Cov
98%
debug
3.0
new
2.0
emit
2.0
CRAP 1.7
« blib/lib/Pipeline/Dispatch.pm ↑ Summary blib/lib/Pipeline/Segment/Async/Fork.pm »
1 package Pipeline::Base;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Pipeline::Error::Construction;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 our $VERSION = "3.12";
10  
11 127 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12 127 my $class = shift;
13 127 my $self = {};
14 127 ▶ if (bless($self, $class)->init( @_ )) {
Branch: 1 branch
BranchTrueFalseTotal
if (bless($self, $class)->init(@_)) { } 125 2 127
15 125 return $self;
16 } else {
17 2 Pipeline::Error::Construction->throw();
18 }
19 }
20  
21 121 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
22 121 my $self = shift;
23 121 return 1;
24 }
25  
26 134 ▶sub debug {
Subroutine debug: called CC=3 SCAR=11.0
Pod documented
27 134 my $self = shift;
28  
29 134 ▶ return 1 if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 134 134
30  
31 134 my $level = shift;
32 134 ▶ if (defined( $level )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) { } 48 86 134
33 48 $self->{ debug } = $level;
34 48 return $self;
35 } else {
36 86 return $self->{ debug };
37 }
38 }
39  
40 66 ▶sub emit {
Subroutine emit: called CC=2 SCAR=6.9
Pod documented
41 66 my $self = shift;
42 66 my $mesg = shift;
43 66 ▶ $self->log( $self->_format_message( $mesg ) ) if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 1 65 66
44 }
45  
46 1 ▶sub log {
Subroutine log: called CC=1 SCAR=0.0
Pod documented
47 1 my $self = shift;
48 1 my $mesg = shift;
49 1 print STDERR $mesg;
50 }
51  
52 1 ▶sub _format_message {
Subroutine _format_message: called CC=1 SCAR=0.0
53 1 my $self = shift;
54 1 my $mesg = shift;
55 1 my $class = ref( $self );
56 1 return "[$class] $mesg\n";
57 }
58  
59 16 1;
60  
61  
62 =head1 NAME
63  
64 Pipeline::Base - base class for all classes in Pipeline distribution
65  
66 =head1 SYNOPSIS
67  
68 use Pipeline::Base;
69  
70 $object = Pipeline::Base->new()
71 $object->debug( 10 );
72 $object->emit("message");
73  
74 =head1 DESCRIPTION
75  
76 C<Pipeline::Base> is a class that provides a basic level of functionality
77 for all classes in the Pipeline system. Most importantly it provides the
78 construction and initialization of new objects.
79  
80 =head1 METHODS
81  
82 =over 4
83  
84 =item CLASS->new()
85  
86 The C<new()> method is a constructor that returns an instance of receiving
87 class.
88  
89 =item init( LIST );
90  
91 C<init()> is called by the constructor, C<new()> and is passed all of its
92 arguments in LIST.
93  
94 =item debug( [ SCALAR ] )
95  
96 The C<debug()> method gets and sets the debug state of the OBJECT. Setting it
97 to a true value will cause messages sent to C<emit()> to be printed to the
98 terminal. If debug() is called as a class method it always will return true.
99  
100 =item emit( SCALAR )
101  
102 C<emit()> is a debugging tool. It will cause the the SCALAR to be formatted and
103 sent to the C<log()> method if the current debugging level is set to a true value.
104  
105 =item log( SCALAR )
106  
107 The C<log()> method will send SCALAR to STDERR by default. It performs no processing
108 of SCALAR and merely sends its results to the error handle. To change your logging
109 mechanism simply override this method in the class as you see fit.
110  
111 =back
112  
113 =head1 AUTHOR
114  
115 James A. Duncan <jduncan@fotango.com>
116  
117 =cut
118  
« blib/lib/Pipeline/Dispatch.pm ↑ Summary blib/lib/Pipeline/Segment/Async/Fork.pm »