| 1 | package Mail::Object; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw[$AUTOLOAD $VERSION ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | $VERSION = '0.0.2'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # This is the base object class for all objects. | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # --------- | ||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 13 | 0 | my $proto = shift; | |||||||||||||||||||
| 14 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | my $self = { }; | |||||||||||||||||||
| 17 | 0 | bless($self, $class); | |||||||||||||||||||
| 18 | 0 | return $self->init(@_); | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # --------- | ||||||||||||||||||||
| 23 | 0 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||
| 25 | 0 | foreach (@_) { @{%{$self}}{keys %{$_}} = values %{$_}; } | |||||||||||||||||||
| 26 | 0 | return $self; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # --------- | ||||||||||||||||||||
| 31 | 0 | ▶ | sub copy { | ||||||||||||||||||
|
Subroutine
copy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||
| 33 | 0 | return $self->deserialize(); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # --------- | ||||||||||||||||||||
| 38 | 0 | ▶ | sub description { | ||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 39 | 0 | my $dataDumper = Data::Dumper->new([+shift, ]); | |||||||||||||||||||
| 40 | 0 | $dataDumper->Purity(1)->Deepcopy(1)->Terse(1)->Indent(1); | |||||||||||||||||||
| 41 | 0 | return $dataDumper->Dump(); | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # --------- | ||||||||||||||||||||
| 46 | 0 | ▶ | sub serialize { | ||||||||||||||||||
|
Subroutine
serialize: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | 0 | my $proto = shift; | |||||||||||||||||||
| 48 | 0 | ▶ | my $anObject = ref($proto) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | ? $proto | ||||||||||||||||||||
| 50 | : shift; | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | my $dataDumper = Data::Dumper->new([$anObject, ]); | |||||||||||||||||||
| 53 | 0 | $dataDumper->Purity(1)->Deepcopy(1)->Terse(1)->Indent(0); | |||||||||||||||||||
| 54 | 0 | return $dataDumper->Dump(); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | # --------- | ||||||||||||||||||||
| 59 | 0 | ▶ | sub deserialize { | ||||||||||||||||||
|
Subroutine
deserialize: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 60 | 0 | my $proto = shift; | |||||||||||||||||||
| 61 | 0 | ▶ | my $aDescription = ref($proto) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | ? $proto->serialize() | ||||||||||||||||||||
| 63 | : shift; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | return eval $aDescription; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # --------- | ||||||||||||||||||||
| 70 | 0 | ▶ | sub class { | ||||||||||||||||||
|
Subroutine
class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | 0 | return ref(+shift); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # --------- | ||||||||||||||||||||
| 76 | 0 | ▶ | sub delete { | ||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 77 | 0 | undef %{; shift}; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | # --------- | ||||||||||||||||||||
| 82 | 0 | ▶ | sub isEqual { | ||||||||||||||||||
|
Subroutine
isEqual: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||
| 84 | 0 | my $object = shift; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | return 1 if $self == $object; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | ▶ | return undef if (keys %{$self} != $object->keys()); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | ▶ | return ($self->hasSubset($object) ? 1 : 0); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | # --------- | ||||||||||||||||||||
| 93 | 0 | ▶ | sub inheritObject { | ||||||||||||||||||
|
Subroutine
inheritObject: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||
| 95 | 0 | my $anObject = shift; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | @{%{$self}}{keys %{$anObject}} = values %{$anObject}; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | return $self; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | # --------- | ||||||||||||||||||||
| 104 | 0 | ▶ | sub respondsTo { | ||||||||||||||||||
|
Subroutine
respondsTo: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||
| 106 | 0 | my $key = shift; | |||||||||||||||||||
| 107 | 0 | ▶ | return (exists $self->{$key}) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | # --------- | ||||||||||||||||||||
| 112 | 0 | ▶ | sub attributes { | ||||||||||||||||||
|
Subroutine
attributes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 113 | 0 | return keys %{; shift}; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | # perlish | ||||||||||||||||||||
| 118 | # --------- | ||||||||||||||||||||
| 119 | 0 | ▶ | sub addAttribute { | ||||||||||||||||||
|
Subroutine
addAttribute: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||
| 121 | 0 | $self->addAttributeWithValue(+shift, ""); | |||||||||||||||||||
| 122 | 0 | return $self; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | # --------- | ||||||||||||||||||||
| 127 | 0 | ▶ | sub addAttributeWithValue { | ||||||||||||||||||
|
Subroutine
addAttributeWithValue: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||||||||||
| 129 | 0 | my $attributeName = shift; | |||||||||||||||||||
| 130 | 0 | my $attributeDefaultValue = shift; | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | ▶ | if (exists $self->{$attributeName}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | warn "Attribute already exists: $attributeName.\n"; | |||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||
| 135 | 0 | return $self->{$attributeName} = $attributeDefaultValue; | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | 0 | return undef; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | # --------- | ||||||||||||||||||||
| 142 | 0 | ▶ | sub deleteAttribute { | ||||||||||||||||||
|
Subroutine
deleteAttribute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 143 | 0 | my $self = shift; | |||||||||||||||||||
| 144 | 0 | my $attributeName = shift; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | ▶ | if (exists $self->{$attributeName}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | 0 | delete $self->{$attributeName}; | |||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||
| 149 | 0 | warn "Cowardly refusing to remove non-existant attribute: $attributeName.\n"; | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | 0 | return undef; | |||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | # --------- | ||||||||||||||||||||
| 156 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 0 | my $name = $AUTOLOAD; | |||||||||||||||||||
| 160 | 0 | $name =~ s/.*://; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 0 | ▶ | if ($name =~ m|^set(.*)|) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | 0 | my $attributeName = lc(substr($1, 0, 1)) . substr($1, 1); | |||||||||||||||||||
| 164 | 0 | ▶ | if (exists $self->{$attributeName}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | 0 | $self->{$attributeName} = shift; | |||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||
| 167 | 0 | warn "$attributeName is not a valid setter method.\n"; | |||||||||||||||||||
| 168 | 0 | return undef; | |||||||||||||||||||
| 169 | } | ||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||
| 171 | 0 | ▶ | if (exists $self->{$name}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 172 | 0 | return $self->{$name}; | |||||||||||||||||||
| 173 | } else { | ||||||||||||||||||||
| 174 | 0 | warn "$name is not a valid accessor method.\n"; | |||||||||||||||||||
| 175 | 0 | return undef; | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | 0 | return $self; | |||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | # --------- | ||||||||||||||||||||
| 183 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 1 | 1337; | |||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | __END__ | ||||||||||||||||||||