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   219246 use warnings;
  46         121  
  46         1547  
3 46     46   272 use strict;
  46         117  
  46         1128  
4 46     46   252 use Carp qw/ confess /;
  46         115  
  46         10983  
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 102128     102128   155255 my $self = shift;
25              
26 102128         272427 (my $attrib = our $AUTOLOAD) =~ s/.*:://;
27 102128 100       232918 if (exists $self->{"_$attrib"}) {
28 102127 100       169396 $self->{"_$attrib"} = shift if @_;
29 102127         322196 return $self->{"_$attrib"};
30             }
31             confess(
32 1         237 sprintf(
33             "Invalid attribute '%s' for class '%s'",
34             $attrib,
35             ref($self)
36             )
37             );
38             }
39              
40 921     921   35714 sub DESTROY { 1 } # the 1 is for coverage
41              
42             1;