| 1 | package Class::AlzaboWrapper; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | $VERSION = '0.14'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Class::AlzaboWrapper::Cursor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | use Exception::Class ( qw( Class::AlzaboWrapper::Exception Class::AlzaboWrapper::Exception::Params ) ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | Class::AlzaboWrapper::Exception->Trace(1); | |||||||||||||||||||
| 13 | 1 | Class::AlzaboWrapper::Exception::Params->Trace(1); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | ▶ | use Params::Validate qw( validate validate_pos validate_with SCALAR UNDEF ARRAYREF HASHREF ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | Params::Validate::validation_options | ||||||||||||||||||||
| 17 | ( on_fail => | ||||||||||||||||||||
| 18 | 0 | ▶ | sub { Class::AlzaboWrapper::Exception::Params->throw | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 19 | 1 | ( message => join '', @_ ) } ); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | my %TableToClass; | |||||||||||||||||||
| 22 | my %ClassToTable; | ||||||||||||||||||||
| 23 | 1 | my %ClassAttributes; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | BEGIN | ||||||||||||||||||||
| 26 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 27 | 1 | foreach my $meth ( qw( select update delete is_live ) ) | |||||||||||||||||||
| 28 | { | ||||||||||||||||||||
| 29 | 0 | ▶ | my $sub = sub { shift->row_object->$meth(@_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 4 | *{ __PACKAGE__ . "::$meth" } = $sub; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | sub import | ||||||||||||||||||||
| 37 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=10.9
| |||||||||||||||||||||
| 38 | 1 | my $class = shift; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # called via 'use base' | ||||||||||||||||||||
| 41 | 1 | ▶ | return unless @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | my %p = | |||||||||||||||||||
| 44 | validate_with( params => \@_, | ||||||||||||||||||||
| 45 | spec => | ||||||||||||||||||||
| 46 | { caller => { type => SCALAR, | ||||||||||||||||||||
| 47 | default => (caller(0))[0] }, | ||||||||||||||||||||
| 48 | base => { type => SCALAR, | ||||||||||||||||||||
| 49 | default => __PACKAGE__ }, | ||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||
| 51 | allow_extra => 1, | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | my $base = delete $p{base}; | |||||||||||||||||||
| 55 | 0 | eval "package $p{caller}; use base '$base'"; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | $class->_make_methods(%p); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | sub _make_methods | ||||||||||||||||||||
| 61 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_make_methods: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 62 | 0 | my $class = shift; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | my %p = validate( @_, | |||||||||||||||||||
| 65 | { skip => { type => SCALAR | ARRAYREF, default => [] }, | ||||||||||||||||||||
| 66 | table => { isa => 'Alzabo::Table' }, | ||||||||||||||||||||
| 67 | caller => { type => SCALAR, default => $class }, | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | my $caller = delete $p{caller}; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | $caller->SetAlzaboTable( delete $p{table} ); | |||||||||||||||||||
| 74 | 0 | $caller->MakeColumnMethods(%p); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | sub SetAlzaboTable | ||||||||||||||||||||
| 78 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
SetAlzaboTable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 79 | 0 | my $class = shift; | |||||||||||||||||||
| 80 | 0 | my ($table) = validate_pos( @_, { isa => 'Alzabo::Table' } ); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | $TableToClass{ $table->name } = $class; | |||||||||||||||||||
| 83 | 0 | $ClassToTable{$class} = $table; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | sub Table | ||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
Table: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 88 | 0 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | Class::AlzaboWrapper::Exception->throw | ||||||||||||||||||||
| 91 | ( error => "Must call SetTable() before calling Table() on $class" ) | ||||||||||||||||||||
| 92 | 0 | ▶ | unless $ClassToTable{$class}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | return $ClassToTable{$class}; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | # deprecated | ||||||||||||||||||||
| 98 | 1 | *table = \&Table; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub MakeColumnMethods | ||||||||||||||||||||
| 101 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
MakeColumnMethods: not called CC=4 SCAR=27.1
Pod
documented
| |||||||||||||||||||||
| 102 | 0 | my $class = shift; | |||||||||||||||||||
| 103 | 0 | my %p = validate( @_, | |||||||||||||||||||
| 104 | { skip => { type => SCALAR | ARRAYREF, default => [] }, | ||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | my %skip = map { $_ => 1 } ref $p{skip} ? @{ $p{skip} } : $p{skip}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | my $table = $class->Table; | |||||||||||||||||||
| 111 | 0 | foreach my $name ( map { $_->name } $table->columns ) | |||||||||||||||||||
| 112 | { | ||||||||||||||||||||
| 113 | 0 | ▶ | next if $skip{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | $class->_RecordAttributeCreation( $class => $name ); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | my $cache_key = '__cache__' . $name; | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 0 | ▶ | my $sub = sub { my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | return $self->{$cache_key} | ||||||||||||||||||||
| 122 | 0 | ▶ | if exists $self->{$cache_key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 0 | $self->{$cache_key} = $self->row_object->select($name); | |||||||||||||||||||
| 125 | 0 | }; | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 128 | 0 | *{"$class\::$name"} = $sub; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | ▶ | sub _RecordAttributeCreation { push @{ $ClassAttributes{ $_[1] } }, $_[2] } | ||||||||||||||||||
|
Subroutine
_RecordAttributeCreation: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 133 | # deprecated | ||||||||||||||||||||
| 134 | 1 | *_record_attribute_creation = \&_RecordAttributeCreation; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | sub new | ||||||||||||||||||||
| 137 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 138 | 0 | my $class = shift; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | my @pk = $class->table->primary_key; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | my @pk_spec = | ||||||||||||||||||||
| 143 | 0 | map { $_->name => { type => SCALAR | UNDEF, optional => 1 } } @pk; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | my %p = | |||||||||||||||||||
| 146 | validate_with( params => \@_, | ||||||||||||||||||||
| 147 | spec => | ||||||||||||||||||||
| 148 | { object => | ||||||||||||||||||||
| 149 | { isa => 'Alzabo::Runtime::Row', optional => 1 }, | ||||||||||||||||||||
| 150 | @pk_spec, | ||||||||||||||||||||
| 151 | }, | ||||||||||||||||||||
| 152 | allow_extra => 1, | ||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | my %pk; | |||||||||||||||||||
| 156 | 0 | foreach my $col (@pk) | |||||||||||||||||||
| 157 | { | ||||||||||||||||||||
| 158 | 0 | ▶ | if ( exists $p{ $col->name } ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | { | ||||||||||||||||||||
| 160 | 0 | $pk{ $col->name } = $p{ $col->name }; | |||||||||||||||||||
| 161 | } | ||||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | 0 | my $row; | |||||||||||||||||||
| 165 | 0 | ▶ | if ( keys %pk == @pk ) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 166 | { | ||||||||||||||||||||
| 167 | 0 | $row = eval { $class->table->row_by_pk( pk => \%pk ) }; | |||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | elsif ( exists $p{object} ) | ||||||||||||||||||||
| 170 | { | ||||||||||||||||||||
| 171 | 0 | $row = $p{object}; | |||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | else | ||||||||||||||||||||
| 174 | { | ||||||||||||||||||||
| 175 | 0 | ▶ | $row = $class->_new_row(%p) if $class->can('_new_row'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 0 | ▶ | return unless $row; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 0 | my $self = bless { row => $row }, $class; | |||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 0 | ▶ | $self->_init(%p) if $self->can('_init'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 0 | return $self; | |||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | sub create | ||||||||||||||||||||
| 188 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
create: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 189 | 0 | my $class = shift; | |||||||||||||||||||
| 190 | 0 | my %p = @_; | |||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 0 | my %values; | |||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 0 | for my $c ( map { $_->name } $class->table->columns ) | |||||||||||||||||||
| 195 | { | ||||||||||||||||||||
| 196 | 0 | ▶ | $values{$c} = delete $p{$c} if exists $p{$c}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 0 | my $row = | |||||||||||||||||||
| 200 | $class->table->insert | ||||||||||||||||||||
| 201 | ( values => \%values ); | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | 0 | return $class->new( object => $row, %p ); | |||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | sub potential | ||||||||||||||||||||
| 207 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
potential: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 208 | 0 | my $class = shift; | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | return | ||||||||||||||||||||
| 211 | 0 | $class->new( object => $class->table->potential_row( values => {@_} ) ); | |||||||||||||||||||
| 212 | } | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 0 | ▶ | sub Columns { shift->table->columns(@_) } | ||||||||||||||||||
|
Subroutine
Columns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 215 | 1 | *Column = \&Columns; | |||||||||||||||||||
| 216 | # deprecated | ||||||||||||||||||||
| 217 | 1 | *columns = \&Columns; | |||||||||||||||||||
| 218 | 1 | *column = \&Columns; | |||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | sub NewCursor | ||||||||||||||||||||
| 221 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
NewCursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 222 | 0 | my $self = shift; | |||||||||||||||||||
| 223 | 0 | my $cursor = shift; | |||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | return | ||||||||||||||||||||
| 226 | 0 | Class::AlzaboWrapper::Cursor->new | |||||||||||||||||||
| 227 | ( cursor => $cursor ); | ||||||||||||||||||||
| 228 | } | ||||||||||||||||||||
| 229 | # deprecated | ||||||||||||||||||||
| 230 | 1 | *cursor = \&NewCursor; | |||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | 0 | ▶ | sub TableToClass { $TableToClass{ $_[1]->name } } | ||||||||||||||||||
|
Subroutine
TableToClass: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 234 | # deprecated | ||||||||||||||||||||
| 235 | 1 | *table_to_class = \&TableToClass; | |||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | sub AlzaboAttributes | ||||||||||||||||||||
| 238 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
AlzaboAttributes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 239 | 0 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 0 | @{ $ClassAttributes{$class} }; | |||||||||||||||||||
| 242 | } | ||||||||||||||||||||
| 243 | # deprecated | ||||||||||||||||||||
| 244 | 1 | *alzabo_attributes = \&AlzaboAttributes; | |||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | 0 | ▶ | sub row_object { $_[0]->{row} } | ||||||||||||||||||
|
Subroutine
row_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | 1 | 1; | |||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | __END__ | ||||||||||||||||||||