line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::Row::NumifyGet; |
2
|
|
|
|
|
|
|
$DBIx::Class::Helper::Row::NumifyGet::VERSION = '2.036000'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Force numeric "context" on numeric columns |
4
|
|
|
|
|
|
|
|
5
|
56
|
|
|
56
|
|
155110
|
use strict; |
|
56
|
|
|
|
|
155
|
|
|
56
|
|
|
|
|
1714
|
|
6
|
56
|
|
|
56
|
|
300
|
use warnings; |
|
56
|
|
|
|
|
107
|
|
|
56
|
|
|
|
|
1457
|
|
7
|
|
|
|
|
|
|
|
8
|
56
|
|
|
56
|
|
291
|
use parent 'DBIx::Class::Row'; |
|
56
|
|
|
|
|
112
|
|
|
56
|
|
|
|
|
375
|
|
9
|
|
|
|
|
|
|
|
10
|
56
|
|
|
56
|
|
3235
|
use Try::Tiny; |
|
56
|
|
|
|
|
124
|
|
|
56
|
|
|
|
|
15087
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_column { |
13
|
83
|
|
|
83
|
1
|
8230
|
my ($self, $col) = @_; |
14
|
|
|
|
|
|
|
|
15
|
83
|
|
|
|
|
243
|
my $value = $self->next::method($col); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$value += 0 if defined($value) and # for nullable and autoinc fields |
18
|
83
|
100
|
66
|
83
|
|
1530
|
try { $self->_is_column_numeric($col) }; |
|
83
|
|
|
|
|
2071
|
|
19
|
|
|
|
|
|
|
|
20
|
83
|
|
|
|
|
4143
|
return $value; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_columns { |
24
|
5
|
|
|
5
|
1
|
46
|
my ($self, $col) = @_; |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
16
|
my %columns = $self->next::method($col); |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
102
|
for (keys %columns) { |
29
|
|
|
|
|
|
|
$columns{$_} += 0 |
30
|
|
|
|
|
|
|
if defined($columns{$_}) and # for nullable and autoinc fields |
31
|
10
|
50
|
33
|
10
|
|
234
|
try { $self->_is_column_numeric($_) }; |
|
10
|
|
|
|
|
234
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
194
|
return %columns; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
DBIx::Class::Helper::Row::NumifyGet - Force numeric "context" on numeric columns |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package MyApp::Schema::Result::Foo_Bar; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw{Helper::Row::NumifyGet Core}); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__PACKAGE__->table('Foo'); |
54
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
55
|
|
|
|
|
|
|
foo => { |
56
|
|
|
|
|
|
|
data_type => 'integer', |
57
|
|
|
|
|
|
|
is_nullable => 0, |
58
|
|
|
|
|
|
|
is_numeric => 1, |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub TO_JSON { |
63
|
|
|
|
|
|
|
return { |
64
|
|
|
|
|
|
|
foo => $self->foo, # this becomes 0 instead of "0" due to context |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 METHODS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 get_column |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This is the method that "converts" the values. It just checks for |
73
|
|
|
|
|
|
|
C<is_numeric> and if that is true it will numify the value. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 get_columns |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This method also "converts" values, but this one is called a lot more rarely. |
78
|
|
|
|
|
|
|
Again, It just checks for C<is_numeric> and if that is true it will numify the |
79
|
|
|
|
|
|
|
value. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
90
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |