| 1 | package Test::Smoke::ObjectBase; | ||||||||||
| 2 | 53 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 53 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 53 | ▶ | use Carp qw/ confess /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 53 | 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 | 111369 | ▶ | sub AUTOLOAD { | ||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
| |||||||||||
| 24 | 111369 | my $self = shift; | |||||||||
| 25 | |||||||||||
| 26 | 111369 | (my $attrib = our $AUTOLOAD) =~ s/.*:://; | |||||||||
| 27 | 111369 | ▶ | if (exists $self->{"_$attrib"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 111368 | ▶ | $self->{"_$attrib"} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 111368 | return $self->{"_$attrib"}; | |||||||||
| 30 | } | ||||||||||
| 31 | confess( | ||||||||||
| 32 | 1 | sprintf( | |||||||||
| 33 | "Invalid attribute '%s' for class '%s'", | ||||||||||
| 34 | $attrib, | ||||||||||
| 35 | ref($self) | ||||||||||
| 36 | ) | ||||||||||
| 37 | ); | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1018 | ▶ | sub DESTROY { 1 } # the 1 is for coverage | ||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | 53 | 1; | |||||||||