line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpusVL::SysParams::Schema::Result::SysInfo; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1253
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
495
|
use Moose; |
|
1
|
|
|
|
|
442869
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
7799
|
use MooseX::NonMoose; |
|
1
|
|
|
|
|
983
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
61642
|
use namespace::autoclean; |
|
1
|
|
|
|
|
6491
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
266
|
use JSON; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Data::Munge qw/elem/; |
11
|
|
|
|
|
|
|
use Scalar::Util qw/reftype looks_like_number/; |
12
|
|
|
|
|
|
|
extends 'DBIx::Class::Core'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp"); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->table("sys_info"); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__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
|
|
|
|
|
|
|
__PACKAGE__->set_primary_key("name"); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub decoded_value |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
return if not defined $self->value; |
63
|
|
|
|
|
|
|
return JSON->new->allow_nonref->decode($self->value); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub viable_type_conversions { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return $self->column_info('data_type')->{extra}->{list} |
70
|
|
|
|
|
|
|
if not $self->data_type; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $options = +{ |
73
|
|
|
|
|
|
|
text => [ qw/textarea array/ ], |
74
|
|
|
|
|
|
|
bool => [ qw/text textarea/ ], |
75
|
|
|
|
|
|
|
array => [ qw/textarea/ ], |
76
|
|
|
|
|
|
|
textarea => [ qw/array/ ], |
77
|
|
|
|
|
|
|
}->{$self->data_type} // []; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
unshift @$options, $self->data_type; |
80
|
|
|
|
|
|
|
return $options; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub convert_to { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
my ($type) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if(!defined $self->data_type || $self->data_type eq '') |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
$self->set_type_from_value; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
die "Cannot convert " . $self->name . " to $type" |
92
|
|
|
|
|
|
|
unless elem $type, $self->viable_type_conversions; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $self->decoded_value |
95
|
|
|
|
|
|
|
if $type eq $self->data_type; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $conv = { |
98
|
|
|
|
|
|
|
"text textarea" => sub { @_ }, |
99
|
|
|
|
|
|
|
"text array" => sub { [@_] }, |
100
|
|
|
|
|
|
|
"bool text" => sub { $_[0] ? "True" : "False" }, |
101
|
|
|
|
|
|
|
"bool textarea" => sub { $_[0] ? "True" : "False" }, |
102
|
|
|
|
|
|
|
"array textarea" => sub { join "\n", @{$_[0]} }, |
103
|
|
|
|
|
|
|
"textarea array" => sub { [ split /\n/, $_[0] ] }, |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $key = join ' ', $self->data_type, $type; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$conv->{$key}->($self->decoded_value); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub set_type_from_value { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
my $value = shift // $self->decoded_value; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
if (ref $value) { |
116
|
|
|
|
|
|
|
if (ref $value =~ /Bool/) { |
117
|
|
|
|
|
|
|
# JSON::Boolean, JSON::PP::Boolean, etc |
118
|
|
|
|
|
|
|
$self->data_type('bool') |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
elsif (reftype $value eq 'HASH') { |
121
|
|
|
|
|
|
|
$self->data_type('object'); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
elsif (reftype $value eq 'ARRAY') { |
124
|
|
|
|
|
|
|
$self->data_type('array'); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
elsif ( reftype $value eq 'SCALAR' |
127
|
|
|
|
|
|
|
and looks_like_number($$value) |
128
|
|
|
|
|
|
|
and ($$value == 0 or $$value == 1) ) |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
$self->data_type('bool'); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
|
|
|
|
|
|
warn "Cannot determine type for " . $self->name . " given " . reftype $value . "."; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
|
|
|
|
|
|
if ($value =~ /\n/) { |
138
|
|
|
|
|
|
|
$self->data_type('textarea'); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
else { |
141
|
|
|
|
|
|
|
$self->data_type('text'); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=pod |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=encoding UTF-8 |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 NAME |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
OpusVL::SysParams::Schema::Result::SysInfo |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 VERSION |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
version 0.20 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 ACCESSORS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 name |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
data_type: 'text' |
169
|
|
|
|
|
|
|
is_nullable: 0 |
170
|
|
|
|
|
|
|
original: {data_type => "varchar"} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 value |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
data_type: 'text' |
175
|
|
|
|
|
|
|
is_nullable: 1 |
176
|
|
|
|
|
|
|
original: {data_type => "varchar"} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 comment |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
data_type: 'text' |
181
|
|
|
|
|
|
|
is_nullable: 1 |
182
|
|
|
|
|
|
|
original: {data_type => "varchar"} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 decoded_value |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Returns the value that the get method returns. |
187
|
|
|
|
|
|
|
This may be any arbitrary data (simple) type. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 viable_type_conversions |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns an arrayref of the types we can probably convert this value to. Also |
192
|
|
|
|
|
|
|
returns the current type. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
For a new row, this simply returns the whole set, because we haven't specified |
195
|
|
|
|
|
|
|
the type yet. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 METHODS |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 convert_to |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=over |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item $data_type |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=back |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Converts the value to the provided data type (see C<viable_type_conversions>), |
208
|
|
|
|
|
|
|
if necessary. Returns the decoded value, i.e. a Perl data structure. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Expected types are, |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * text |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item * array |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * textarea |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=back |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 set_type_from_value |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=over |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item $value |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=back |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Attempts to guess the data type of the provided value, which defaults to the |
231
|
|
|
|
|
|
|
row's value if not provided. Sets the C<data_type> property on the field, but |
232
|
|
|
|
|
|
|
doesn't save it. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
OpusVL - www.opusvl.com |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This software is copyright (c) 2011 - 2016 by OpusVL - www.opusvl.com. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
243
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |