| 1 | #$Id: Deep.pm 25 2005-09-11 09:48:14Z kentaro $ | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Class::AutoAccess::Deep; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 4 | my ($class, $fields) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | _croak('argument must be passed in as hashref') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $fields or ref $fields eq "HASH"
MC/DC50%1/2
defined $fields or ref $fields eq "HASH"
defined $fields
ref $fields eq "HASH"
Truth table66%2/3
A or B
A= defined $fieldsB= ref $fields eq "HASH"
| |||||||||||||||||||||||||||||
| 16 | unless defined $fields || ref $fields eq 'HASH'; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | return bless $fields, $class; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 22 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 23 | 10 | (my $field = $AUTOLOAD) =~ s/.*:://; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 10 | ▶ | return if $field eq 'DESTROY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # XXX | ||||||||||||||||||||||||||||
| 28 | # croaks when you attempt to access an undefined field | ||||||||||||||||||||||||||||
| 29 | # do you need this feature? | ||||||||||||||||||||||||||||
| 30 | _croak("Field $field does not exists") | ||||||||||||||||||||||||||||
| 31 | 8 | ▶ | unless exists $self->{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | $self->{$field} = _get_linkedobj($_[0]); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||
| 37 | 5 | $self->{$field} = _get_linkedobj($self->{$field}); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 7 | return $self->{$field}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 7 | ▶ | sub _get_linkedobj { | ||||||||||||||||||||||||||
|
Subroutine
_get_linkedobj: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 7 | my $value= shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 7 | ▶ | if (ref($value) eq 'HASH'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | return __PACKAGE__->new($value); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 6 | return $value; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub _croak { | ||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 55 | 2 | my $msg = shift; | |||||||||||||||||||||||||||
| 56 | 2 | Carp::croak($msg); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | return; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||