| 1 | package Mojolicious::Plugin::Tables::Model::Row; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | ▶ | use base 'DBIx::Class::Core'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | __PACKAGE__-> load_components('InflateColumn::DateTime'); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | use overload | ||||||||||||||||||||
| 11 | 12 | ▶ | '""' => sub { shift->stringify_safely }, | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 4 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 3 | fallback => 1; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | # errors during stringification of a db object can sometimes trigger | ||||||||||||||||||||
| 16 | # deep recursion by well-meaning error messages deep in ORM internals. | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 12 | ▶ | sub stringify_safely { | ||||||||||||||||||
|
Subroutine
stringify_safely: called CC=2 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||
| 19 | 12 | my $self = shift; | |||||||||||||||||||
| 20 | 12 | ▶ | return eval { $self->stringify } // do { | ||||||||||||||||||
|
Condition33%1/3
eval {
do {
$self->stringify
}
} // do {
my $err = $@;
my $class = ref $self;
my $fallback = "[*$class]" . $self->id;
$self->log->error("stringifying ${fallback}: $err");
$fallback
}
MC/DC0%0/2
eval {
do {
$self->stringify
}
} // do {
my $err = $@;
my $class = ref $self;
my $fallback = "[*$class]" . $self->id;
$self->log->error("stringifying ${fallback}: $err");
$fallback
}
eval {
do {
$self->stringify
}
}
do {
my $err = $@;
my $class = ref $self;
my $fallback = "[*$class]" . $self->id;
$self->log->error("stringifying ${fallback}: $err");
$fallback
}
Truth table33%1/3
A // B
A= eval {
do {
$self->stringify
}
}B= do {
my $err = $@;
my $class = ref $self;
my $fallback = "[*$class]" . $self->id;
$self->log->error("stringifying ${fallback}: $err");
$fallback
}
| |||||||||||||||||||||
| 21 | 0 | my $err = $@; | |||||||||||||||||||
| 22 | 0 | my $class = ref $self; | |||||||||||||||||||
| 23 | 0 | my $fallback = "[*$class]".$self->id; | |||||||||||||||||||
| 24 | 0 | $self->log->error("stringifying $fallback: $err"); | |||||||||||||||||||
| 25 | 0 | $fallback | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # override this for each ResultClass. | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 12 | ▶ | sub stringify { | ||||||||||||||||||
|
Subroutine
stringify: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||
| 32 | 12 | my $self = shift; | |||||||||||||||||||
| 33 | 12 | ▶ | my $cd = $self->can('cd') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | ? (':'.$self->cd) | ||||||||||||||||||||
| 35 | : $self->compound_ids; | ||||||||||||||||||||
| 36 | 12 | ▶ | my $ds = $self->can('description')? $self->description: | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 37 | $self->can('name' )? $self->name: | ||||||||||||||||||||
| 38 | ''; | ||||||||||||||||||||
| 39 | 12 | my $label = $self->result_source->source_name; | |||||||||||||||||||
| 40 | 12 | ▶ | sprintf '[%s] %s%s', $label, $cd, ($ds? " - $ds":'') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | sub log { shift->result_source->schema->log } | ||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 16 | ▶ | sub compound_ids { | ||||||||||||||||||
|
Subroutine
compound_ids: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 46 | 16 | my $self = shift; | |||||||||||||||||||
| 47 | 16 | join ('-|-', map { $self->get_column($_) } $self->primary_columns); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 4 | ▶ | sub present { | ||||||||||||||||||
|
Subroutine
present: called CC=9 SCAR=26.3
Pod
undocumented
| |||||||||||||||||||||
| 51 | 4 | my ($self, $column, $info, %opts) = @_; | |||||||||||||||||||
| 52 | 4 | my $class = ref $self; | |||||||||||||||||||
| 53 | #$self->log->debug("present $column for $class using " . Dumper($info)); | ||||||||||||||||||||
| 54 | 4 | ▶ | my $type = $info->{data_type} || 'varchar'; | ||||||||||||||||||
|
Condition50%1/2
$info->{'data_type'} || 'varchar'
MC/DC0%0/1
$info->{'data_type'} || 'varchar'
$info->{'data_type'}
Truth table50%1/2
A
A= $info->{'data_type'}
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | ▶ | my $val = $self->$column // return; | ||||||||||||||||||
|
Condition50%1/2
$self->$column // (return)
MC/DC0%0/1
$self->$column // (return)
$self->$column
Truth table50%1/2
A
A= $self->$column
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 4 | for ($type) { | |||||||||||||||||||
| 59 | 4 | ▶ | /timestamp/ && return ($opts{foredit}? $val->iso8601: $val->strftime('%F %T')); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 60 | 4 | ▶ | /date/ && return ($val->ymd); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 4 | ▶ | /boolean/ && return ($val?'Yes':'No'); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 4 | return $val | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | # generate the full pick-list that lets the fk $column pick from its parent, | ||||||||||||||||||||
| 67 | # in a structure suitable for the 'select_field' tag. This version gets all | ||||||||||||||||||||
| 68 | # (limited by safety check) but inherited versions are expected to do more | ||||||||||||||||||||
| 69 | # context-sensitive filtering. Will work as a class method. | ||||||||||||||||||||
| 70 | 0 | ▶ | sub options { | ||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | #my ($self, $column, $cinfo, $pinfo, $schema, $bytable) = @_; | ||||||||||||||||||||
| 72 | 0 | my ($xxx1, $xxxxx2, $xxxx3, $pinfo, $schema, $bytable) = @_; | |||||||||||||||||||
| 73 | 0 | my $ptable = $pinfo->{ptable}; | |||||||||||||||||||
| 74 | 0 | my $ptabinfo = $bytable->{$ptable}; | |||||||||||||||||||
| 75 | 0 | my $psource = $ptabinfo->{source}; | |||||||||||||||||||
| 76 | 0 | my $prs = $schema->resultset($psource); | |||||||||||||||||||
| 77 | 0 | my $where = {}; | |||||||||||||||||||
| 78 | 0 | my $attrs = {rows=>200}; | |||||||||||||||||||
| 79 | my @options = map { | ||||||||||||||||||||
| 80 | 0 | [ "$_" => $_->id ] | |||||||||||||||||||
| 81 | } $prs->search($where, $attrs); | ||||||||||||||||||||
| 82 | 0 | return \@options; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub nuke { | ||||||||||||||||||
|
Subroutine
nuke: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||
| 87 | 0 | my $s = $self->result_source; | |||||||||||||||||||
| 88 | 0 | my $schema = $s->schema; | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | my @collections = grep { $s->relationship_info($_)->{attrs}{accessor} eq 'multi' } | |||||||||||||||||||
| 91 | $s->relationships; | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | my $i = 0; | |||||||||||||||||||
| 94 | 0 | ▶ | $schema->txn_do( sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 95 | 0 | for my $collection (@collections) { | |||||||||||||||||||
| 96 | 0 | $i += $_->nuke for $self->$collection->all; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | 0 | $self->delete; | |||||||||||||||||||
| 99 | 0 | ++$i | |||||||||||||||||||
| 100 | } ) | ||||||||||||||||||||
| 101 | 0 | } | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 3 | 1; | |||||||||||||||||||
| 104 | |||||||||||||||||||||