File Coverage

blib/lib/Test/Smoke/ObjectBase.pm
Criterion Covered Total %
statement 16 16 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 25 25 100.0


line stmt bran cond sub pod time code
1             package Test::Smoke::ObjectBase;
2 46     46   176438 use warnings;
  46         98  
  46         1328  
3 46     46   201 use strict;
  46         82  
  46         853  
4 46     46   197 use Carp qw/ confess /;
  46         83  
  46         8208  
5              
6             our $VERSION = '0.001';
7              
8             =head1 NAME
9              
10             Test::Smoke:ObjectBase - Base class for objects (AUTOLOADed accessors)
11              
12             =head1 DESCRIPTION
13              
14             This base class provides accessors via AUTOLOAD for hashkeys that start with
15             an underscore.
16              
17             $self->{_name} gives $self->name()
18              
19             The accessors are 'getters' as well as 'setters'.
20              
21             =cut
22              
23             sub AUTOLOAD {
24 102140     102140   124993 my $self = shift;
25              
26 102140         217927 (my $attrib = our $AUTOLOAD) =~ s/.*:://;
27 102140 100       187164 if (exists $self->{"_$attrib"}) {
28 102139 100       134189 $self->{"_$attrib"} = shift if @_;
29 102139         262392 return $self->{"_$attrib"};
30             }
31             confess(
32 1         156 sprintf(
33             "Invalid attribute '%s' for class '%s'",
34             $attrib,
35             ref($self)
36             )
37             );
38             }
39              
40 921     921   1041404 sub DESTROY { 1 } # the 1 is for coverage
41              
42             1;