| 1 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Object::Annotate; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | $Object::Annotate::VERSION = '0.024'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: mix in logging-to-database to objects (deprecated) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use UNIVERSAL::moniker 0.01; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # We'll store the constructed Class::DBI subclasses here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # $class_for->{ $dsn }->{ $table } = $class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my $class_for = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # We'll keep a counter, here, to use to form unique class names. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my $current_suffix = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # The "id" column isn't here because we want it first, always. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | my %note_columns = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | mandatory => [ qw(class object_id created) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # I plan to use these values in the future. -- rjbs, 2006-01-13 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # default => [ qw(event attr old_val new_val via comment expire_time) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | default => [ qw(event attr old_val new_val via comment expire_time) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | use Sub::Exporter 0.92 -setup => { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | groups => { annotator => \&setup_class }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $class = (ref $self) ? ref $self : $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $target | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | = sprintf '%s::Singularity::0x%08x', $class, ++$current_suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->setup_class($target, $arg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $singularity = \do { undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | bless $singularity => $target; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub setup_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | my ($self, $name, $arg, $col) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_class: called CC=12 SCAR=31.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $arg->{db}{dsn} ||= $self->default_dsn; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"db"}{"dsn"} ||= $self->default_dsn
MC/DC0%0/2
$arg->{"db"}{"dsn"} ||= $self->default_dsn
$arg->{"db"}{"dsn"}
$self->default_dsn
Truth table33%1/3
A ||= B
A= $arg->{"db"}{"dsn"}B= $self->default_dsn
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | $arg->{db}{table} ||= $self->default_table; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"db"}{"table"} ||= $self->default_table
MC/DC0%0/2
$arg->{"db"}{"table"} ||= $self->default_table
$arg->{"db"}{"table"}
$self->default_table
Truth table33%1/3
A ||= B
A= $arg->{"db"}{"table"}B= $self->default_table
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | $arg->{db}{user} ||= $self->default_user; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"db"}{"user"} ||= $self->default_user
MC/DC0%0/2
$arg->{"db"}{"user"} ||= $self->default_user
$arg->{"db"}{"user"}
$self->default_user
Truth table33%1/3
A ||= B
A= $arg->{"db"}{"user"}B= $self->default_user
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | $arg->{db}{pass} ||= $self->default_pass; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"db"}{"pass"} ||= $self->default_pass
MC/DC0%0/2
$arg->{"db"}{"pass"} ||= $self->default_pass
$arg->{"db"}{"pass"}
$self->default_pass
Truth table33%1/3
A ||= B
A= $arg->{"db"}{"pass"}B= $self->default_pass
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | $arg->{db}{sequence} ||= $self->_default_sequence; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"db"}{"sequence"} ||= $self->_default_sequence
MC/DC0%0/2
$arg->{"db"}{"sequence"} ||= $self->_default_sequence
$arg->{"db"}{"sequence"}
$self->_default_sequence
Truth table33%1/3
A ||= B
A= $arg->{"db"}{"sequence"}B= $self->_default_sequence
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | ▶ | if ($arg->{noun} xor $arg->{verb}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition25%1/4
$arg->{"noun"} xor $arg->{"verb"}
MC/DC0%0/2
$arg->{"noun"} xor $arg->{"verb"}
$arg->{"noun"}
$arg->{"verb"}
Truth table25%1/4
A xor B
A= $arg->{"noun"}B= $arg->{"verb"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | Carp::croak 'you must supply either both or neither "noun" and "verb"'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ▶ | } elsif (not ($arg->{noun} or $arg->{verb})) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{'noun'} || $arg->{'verb'}
MC/DC0%0/2
$arg->{'noun'} || $arg->{'verb'}
$arg->{'noun'}
$arg->{'verb'}
Truth table33%1/3
A || B
A= $arg->{'noun'}B= $arg->{'verb'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | @$arg{qw(noun verb)} = qw(annotations annotate); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my $class = $self->class_for($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | my $obj_class = $arg->{obj_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | my %build_option = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | obj_class => $obj_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | id_attr => $arg->{id_attr} || 'id', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | noun => $arg->{noun}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | verb => $arg->{verb}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$arg->{'id_attr'} || 'id'
MC/DC100%1/1
$arg->{'id_attr'} || 'id'
$arg->{'id_attr'}
Truth table100%2/2
A
A= $arg->{'id_attr'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | my $annotator = $self->build_annotator({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | %build_option, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | columns => $arg->{columns}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | set_time => ($arg->{db}{dsn} && (scalar $arg->{db}{dsn} =~ /SQLite/)), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg->{'db'}{'dsn'} && scalar $arg->{'db'}{'dsn'} =~ /SQLite/
MC/DC0%0/1
$arg->{'db'}{'dsn'} && scalar $arg->{'db'}{'dsn'} =~ /SQLite/
$arg->{'db'}{'dsn'}
Truth table50%1/2
A
A= $arg->{'db'}{'dsn'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | my $return = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 25 | ▶ | "$arg->{noun}_class" => sub { $class }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | $arg->{verb} => $annotator, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | "search_$arg->{noun}" => $self->build_searcher(\%build_option), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | sub class_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_for: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $dsn = $arg->{db}{dsn}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | my $table = $arg->{db}{table}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | my $user = $arg->{db}{user}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | my $pass = $arg->{db}{pass}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Try to find an already-constructed class. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | my $class = ! $arg->{extra_setup} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | && exists $class_for->{ $dsn } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | && exists $class_for->{ $dsn }->{ $table } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | && $class_for->{ $dsn }->{ $table }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%6/9
!$arg->{'extra_setup'} && exists $class_for->{$dsn} && exists $class_for->{$dsn}{$table} && $class_for->{$dsn}{$table}
not $arg->{"extra_setup"} and exists $class_for->{$dsn} and exists $class_for->{$dsn}{$table}
not $arg->{"extra_setup"} and exists $class_for->{$dsn}
MC/DC25%1/4
!$arg->{'extra_setup'} && exists $class_for->{$dsn} && exists $class_for->{$dsn}{$table} && $class_for->{$dsn}{$table}
not $arg->{"extra_setup"}
exists $class_for->{$dsn}
exists $class_for->{$dsn}{$table}
$class_for->{$dsn}{$table}
Truth table40%2/5
not(A) and B and C && D
A= not $arg->{"extra_setup"}B= exists $class_for->{$dsn}C= exists $class_for->{$dsn}{$table}D= $class_for->{$dsn}{$table}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | return $class if $class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # If we have no class built for this combination, build it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $class = $self->construct_cdbi_class({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | dsn => $dsn, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | user => $user, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | pass => $pass, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | table => $table, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | columns => $arg->{columns}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | sequence => $arg->{db}{sequence}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | base_class => $arg->{base_class}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | $arg->{extra_setup}->($class) if $arg->{extra_setup}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub default_dsn { $ENV{OBJ_ANNOTATE_DSN}; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_dsn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub default_table { $ENV{OBJ_ANNOTATE_TABLE}; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | sub default_user { $ENV{OBJ_ANNOTATE_USER}; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_user: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | sub default_pass { $ENV{OBJ_ANNOTATE_PASS}; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_pass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub default_base_class { 'Class::DBI' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_base_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ▶ | sub _default_sequence { } | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_sequence: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | sub construct_cdbi_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | my ($class, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
construct_cdbi_class: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my $new_class | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | = sprintf '%s::Construct::0x%08x', __PACKAGE__, ++$current_suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | $arg->{base_class} ||= $class->default_base_class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"base_class"} ||= $class->default_base_class
MC/DC0%0/2
$arg->{"base_class"} ||= $class->default_base_class
$arg->{"base_class"}
$class->default_base_class
Truth table33%1/3
A ||= B
A= $arg->{"base_class"}B= $class->default_base_class
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | eval "require $arg->{base_class};" or die $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | @{$new_class . '::ISA'} = $arg->{base_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | if ($arg->{dsn}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $new_class->connection($arg->{dsn}, $arg->{user}, $arg->{pass}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $new_class->table($arg->{table}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | my @columns = @{ $note_columns{mandatory} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | my @extra_columns = @{ $arg->{columns} || $note_columns{default} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | push @columns, @extra_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | $new_class->columns(All => ('id', @columns)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | $new_class->sequence($arg->{sequence}) if $arg->{sequence}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $new_class->db_Main->{ AutoCommit } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | return $class_for->{ $arg->{dsn} || '' }->{ $arg->{table} } = $new_class; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg->{'dsn'} || ''
MC/DC0%0/1
$arg->{'dsn'} || ''
$arg->{'dsn'}
Truth table50%1/2
A
A= $arg->{'dsn'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sub build_annotator { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_annotator: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | my $obj_class = $arg->{obj_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | my $id_attr = $arg->{id_attr}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | my $set_time = $arg->{set_time}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | my @columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | = $arg->{columns} ? @{ $arg->{columns} } : @{ $note_columns{default} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | my $noun = $arg->{noun}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | my $annotator = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # This $arg purposefully shadows the previous; I don't want to enclose | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # those args. -- rjbs, 2006-01-05 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | ▶ | my $obj_class = $arg->{obj_class} || $self->moniker; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{'obj_class'} || $self->moniker
MC/DC0%0/2
$arg->{'obj_class'} || $self->moniker
$arg->{'obj_class'}
$self->moniker
Truth table33%1/3
A || B
A= $arg->{'obj_class'}B= $self->moniker
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9 | my $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 9 | ▶ | if (ref $id_attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | $id = $$id_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | $id = $self->$id_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | ▶ | Carp::croak "couldn't get id for $self via $id_attr" unless $id; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # build up only those attributes we declared | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 9 | my %attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | for (@columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 63 | ▶ | next unless exists $arg->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 17 | $attr{$_} = $arg->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 9 | ▶ | $attr{created} = time if $set_time; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | my $class_name_method = "$noun\_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | my $request = $self->$class_name_method->create({ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | class => $obj_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | object_id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | %attr, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | return $request; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | return $annotator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | sub build_searcher { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_searcher: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | my $obj_class = $arg->{obj_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | my $id_attr = $arg->{id_attr}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | my $noun = $arg->{noun}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | my $searcher = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 10 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 10 | ▶ | my $obj_class = $arg->{obj_class} || $self->moniker; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{'obj_class'} || $self->moniker
MC/DC0%0/2
$arg->{'obj_class'} || $self->moniker
$arg->{'obj_class'}
$self->moniker
Truth table33%1/3
A || B
A= $arg->{'obj_class'}B= $self->moniker
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 10 | ▶ | $arg ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg ||= {}
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | my $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 10 | ▶ | if (ref $id_attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | $id = $$id_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } elsif (ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | $id = $self->$id_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | ▶ | Carp::croak "couldn't get id for $self via $id_attr" unless $id; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 10 | $arg->{class} = $obj_class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 10 | ▶ | $arg->{object_id} = $id if defined $id and not exists $arg->{object_id}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $id and not exists $arg->{"object_id"}
MC/DC50%1/2
defined $id and not exists $arg->{"object_id"}
defined $id
not exists $arg->{"object_id"}
Truth table66%2/3
A and not(B)
A= defined $idB= not exists $arg->{"object_id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 10 | my $class_name_method = "$noun\_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 10 | $self->$class_name_method->search(%$arg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | '2. see footnote #1'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||