blib/lib/TAP/Object.pm

filter: Statementstmt 50.8% 30 / 59 Branchbran 37.5% 6 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 52.9% 9 / 17 Podpod 100% 4 / 4 totaltotal 51.0% 49 / 96 CC 11 SCAR 12.0
CC
11
Cov
48%
_construct
7.1
_construct
7.1
__ANON__
2.5
CRAP 3.3
« blib/lib/TAP/Parser/SourceHandler/File.pm ↑ Summary blib/lib/TAP/Base.pm »
1 package TAP::Object;
2  
3 53 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 53 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 TAP::Object - Base class that provides common functionality to all C<TAP::*> modules
9  
10 =head1 VERSION
11  
12 Version 3.52
13  
14 =cut
15  
16 53 our $VERSION = '3.52';
17  
18 =head1 SYNOPSIS
19  
20 package TAP::Whatever;
21  
22 use strict;
23  
24 use base 'TAP::Object';
25  
26 # new() implementation by TAP::Object
27 sub _initialize {
28 my ( $self, @args) = @_;
29 # initialize your object
30 return $self;
31 }
32  
33 # ... later ...
34 my $obj = TAP::Whatever->new(@args);
35  
36 =head1 DESCRIPTION
37  
38 C<TAP::Object> provides a default constructor and exception model for all
39 C<TAP::*> classes. Exceptions are raised using L<Carp>.
40  
41 =head1 METHODS
42  
43 =head2 Class Methods
44  
45 =head3 C<new>
46  
47 Create a new object. Any arguments passed to C<new> will be passed on to the
48 L</_initialize> method. Returns a new object.
49  
50 =cut
51  
52 3489 ▶sub new {
Subroutine new: called CC=1 SCAR=1.2
Pod documented
53 0 ▶ return bless({}, shift)->_initialize(@_);
Subroutine new: not called CC=1 SCAR=1.2
Pod documented
54 }
55  
56 =head2 Instance Methods
57  
58 =head3 C<_initialize>
59  
60 Initializes a new object. This method is a stub by default, you should override
61 it as appropriate.
62  
63 I<Note:> L</new> expects you to return C<$self> or raise an exception. See
64 L</_croak>, and L<Carp>.
65  
66 =cut
67  
68 107 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=1.2
69 0 ▶ return $_[0];
Subroutine _initialize: not called CC=1 SCAR=1.2
70 }
71  
72 =head3 C<_croak>
73  
74 Raise an exception using C<croak> from L<Carp>, eg:
75  
76 $self->_croak( 'why me?', 'aaarrgh!' );
77  
78 May also be called as a I<class> method.
79  
80 $class->_croak( 'this works too' );
81  
82 =cut
83  
84 22 ▶sub _croak {
Subroutine _croak: called CC=1 SCAR=2.2
85 0 ▶ my $proto = shift;
Subroutine _croak: not called CC=1 SCAR=2.2
86 0 require Carp;
87 0 Carp::croak(@_);
88 0 return;
89 }
90  
91 =head3 C<_confess>
92  
93 Raise an exception using C<confess> from L<Carp>, eg:
94  
95 $self->_confess( 'why me?', 'aaarrgh!' );
96  
97 May also be called as a I<class> method.
98  
99 $class->_confess( 'this works too' );
100  
101 =cut
102  
103 0 ▶sub _confess {
Subroutine _confess: not called CC=1 SCAR=6.9
104 0 ▶ my $proto = shift;
Subroutine _confess: not called CC=1 SCAR=6.9
105 0 require Carp;
106 0 Carp::confess(@_);
107 0 return;
108 }
109  
110 =head3 C<_construct>
111  
112 Create a new instance of the specified class.
113  
114 =cut
115  
116 368 ▶sub _construct {
Subroutine _construct: called CC=4 SCAR=19.6
117 0 ▶ my ( $self, $class, @args ) = @_;
Subroutine _construct: not called CC=4 SCAR=19.6
118  
119 0 ▶ $self->_croak("Bad module name $class")
Branch: 2 branches
BranchTrueFalseTotal
unless $class =~ /^ \w+ (?: :: \w+ ) *$/x 0 368 368
unless $class =~ /^ \w+ (?: :: \w+ ) *$/x 0 0 0
120 unless $class =~ /^ \w+ (?: :: \w+ ) *$/x;
121  
122 0 ▶ unless ( $class->can('new') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($class->can("new")) 45 323 368
unless ($class->can("new")) 0 0 0
123 0 local $@;
124 0 eval "require $class";
125 0 ▶ $self->_croak("Can't load $class: $@") if $@;
Branch: 2 branches
BranchTrueFalseTotal
if $@ 0 45 45
if $@ 0 0 0
126 }
127  
128 0 return $class->new(@args);
129 }
130  
131 =head3 C<mk_methods>
132  
133 Create simple getter/setters.
134  
135 __PACKAGE__->mk_methods(@method_names);
136  
137 =cut
138  
139 62 ▶sub mk_methods {
Subroutine mk_methods: called CC=2 SCAR=8.4
Pod documented
140 0 ▶ my ( $class, @methods ) = @_;
Subroutine mk_methods: not called CC=2 SCAR=8.4
Pod documented
141 0 for my $method_name (@methods) {
142 0 my $method = "${class}::$method_name";
143 53 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
144 20920 ▶ *$method = sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
145 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=2 SCAR=9.2
146 0 ▶ $self->{$method_name} = shift if @_;
Branch: 2 branches
BranchTrueFalseTotal
if @_ 5807 15113 20920
if @_ 0 0 0
147 0 return $self->{$method_name};
148 0 };
149 }
150 }
151  
152 53 1;
153  
« blib/lib/TAP/Parser/SourceHandler/File.pm ↑ Summary blib/lib/TAP/Base.pm »