| 1 | package OpusVL::SysParams::Schema::Result::SysInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Data::Munge qw/elem/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Scalar::Util qw/reftype looks_like_number/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | extends 'DBIx::Class::Core'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | __PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | __PACKAGE__->table("sys_info"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | __PACKAGE__->add_columns( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | "name", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | data_type => "text", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | is_nullable => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | original => { data_type => "varchar" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | "label", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | data_type => "text", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | is_nullable => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | original => { data_type => "varchar" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | "value", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | data_type => "text", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | is_nullable => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | original => { data_type => "varchar" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | "comment", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | data_type => "text", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | is_nullable => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | original => { data_type => "varchar" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | data_type => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # NOTE: don't set a default value for objects, because the current data_type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # restricts what other data_types we can select. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | data_type => 'enum', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | is_nullable => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | extra => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | list => [ qw/text textarea object array bool/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | labels => [ "Text", "Multiline Text", "Object", "List", "Boolean" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | __PACKAGE__->set_primary_key("name"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub decoded_value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decoded_value: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | return if not defined $self->value; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | return JSON->new->allow_nonref->decode($self->value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub viable_type_conversions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
viable_type_conversions: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | return $self->column_info('data_type')->{extra}->{list} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if not $self->data_type; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | my $options = +{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | text => [ qw/textarea array/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | bool => [ qw/text textarea/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | array => [ qw/textarea/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | textarea => [ qw/array/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | }->{$self->data_type} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
{"text", ["textarea", "array"], "bool", ["text", "textarea"], "array", ["textarea"], "textarea", ["array"]}->{$self->data_type} // []
MC/DC0%0/1
{"text", ["textarea", "array"], "bool", ["text", "textarea"], "array", ["textarea"], "textarea", ["array"]}->{$self->data_type} // []
{"text", ["textarea", "array"], "bool", ["text", "textarea"], "array", ["textarea"], "textarea", ["array"]}->{$self->data_type}
Truth table50%1/2
A
A= {"text", ["textarea", "array"], "bool", ["text", "textarea"], "array", ["textarea"], "textarea", ["array"]}->{$self->data_type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | unshift @$options, $self->data_type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | return $options; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub convert_to { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_to: called CC=5 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | my ($type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | if(!defined $self->data_type || $self->data_type eq '') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->data_type or $self->data_type eq ""
MC/DC50%1/2
not defined $self->data_type or $self->data_type eq ""
not defined $self->data_type
$self->data_type eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->data_typeB= $self->data_type eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | $self->set_type_from_value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | die "Cannot convert " . $self->name . " to $type" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | unless elem $type, $self->viable_type_conversions; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | return $self->decoded_value | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | if $type eq $self->data_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | my $conv = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | "text textarea" => sub { @_ }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | "text array" => sub { [@_] }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | "bool text" => sub { $_[0] ? "True" : "False" }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | "bool textarea" => sub { $_[0] ? "True" : "False" }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | "array textarea" => sub { join "\n", @{$_[0]} }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | "textarea array" => sub { [ split /\n/, $_[0] ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | my $key = join ' ', $self->data_type, $type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | $conv->{$key}->($self->decoded_value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | sub set_type_from_value { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_type_from_value: called CC=11 SCAR=35.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | my $value = shift // $self->decoded_value; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() // $self->decoded_value
MC/DC0%0/2
shift() // $self->decoded_value
shift()
$self->decoded_value
Truth table66%2/3
A // B
A= shift()B= $self->decoded_value
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | if (ref $value =~ /Bool/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # JSON::Boolean, JSON::PP::Boolean, etc | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->data_type('bool') | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif (reftype $value eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->data_type('object'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | elsif (reftype $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | $self->data_type('array'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ▶ | elsif ( reftype $value eq 'SCALAR' | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
builtin::reftype($value) eq "SCALAR" and &looks_like_number($$value) and $$value == 0 || $$value == 1
builtin::reftype($value) eq "SCALAR" and &looks_like_number($$value)
$$value == 0 or $$value == 1
MC/DC0%0/4
builtin::reftype($value) eq "SCALAR" and &looks_like_number($$value) and $$value == 0 || $$value == 1
builtin::reftype($value) eq "SCALAR"
&looks_like_number($$value)
$$value == 0
$$value == 1
Truth table0%0/5
A and B and C or D
A= builtin::reftype($value) eq "SCALAR"B= &looks_like_number($$value)C= $$value == 0D= $$value == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | and looks_like_number($$value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | and ($$value == 0 or $$value == 1) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $self->data_type('bool'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | warn "Cannot determine type for " . $self->name . " given " . reftype $value . "."; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | if ($value =~ /\n/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->data_type('textarea'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | $self->data_type('text'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||