line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::Row::Enumeration; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Add methods for emum values |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
305886
|
use v5.10.1; |
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
8
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
888
|
use Ref::Util (); |
|
2
|
|
|
|
|
3028
|
|
|
2
|
|
|
|
|
61
|
|
11
|
2
|
|
|
2
|
|
14
|
use Sub::Quote (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
835
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# RECOMMEND PREREQ: Ref::Util::XS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 'v0.1.7'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# The names of all methods installed by this module. |
18
|
|
|
|
|
|
|
my %MINE; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add_columns { |
23
|
8
|
|
|
8
|
0
|
418679
|
my ( $self, @cols ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
|
|
35
|
$self->next::method(@cols); |
26
|
|
|
|
|
|
|
|
27
|
8
|
|
33
|
|
|
5510
|
my $class = Ref::Util::is_ref($self) || $self; |
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
|
|
19
|
foreach my $col (@cols) { |
30
|
|
|
|
|
|
|
|
31
|
42
|
100
|
|
|
|
2331
|
next if ref $col; |
32
|
|
|
|
|
|
|
|
33
|
23
|
|
|
|
|
55
|
$col =~ s/^\+//; |
34
|
23
|
|
|
|
|
460
|
my $info = $self->column_info($col); |
35
|
|
|
|
|
|
|
|
36
|
23
|
100
|
|
|
|
1956
|
next unless $info->{data_type} eq 'enum'; |
37
|
|
|
|
|
|
|
|
38
|
20
|
50
|
|
|
|
47
|
next unless exists $info->{extra}{list}; |
39
|
|
|
|
|
|
|
|
40
|
20
|
|
100
|
25
|
|
104
|
my $handlers = $info->{extra}{handles} //= sub { "is_" . $_[0] }; |
|
25
|
|
|
|
|
59
|
|
41
|
|
|
|
|
|
|
|
42
|
20
|
50
|
|
|
|
47
|
next unless $handlers; |
43
|
|
|
|
|
|
|
|
44
|
20
|
100
|
|
|
|
52
|
if ( Ref::Util::is_plain_coderef($handlers) ) { |
45
|
|
|
|
|
|
|
$info->{extra}{handles} = { |
46
|
|
|
|
|
|
|
map { |
47
|
|
|
|
|
|
|
|
48
|
40
|
100
|
|
|
|
100
|
if ( my $method = $handlers->( $_, $col, $class ) ) { |
49
|
35
|
|
|
|
|
198
|
( $method => $_ ) |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
() |
53
|
5
|
|
|
|
|
45
|
} |
54
|
|
|
|
|
|
|
|
55
|
15
|
|
|
|
|
24
|
} @{ $info->{extra}{list} } |
|
15
|
|
|
|
|
40
|
|
56
|
|
|
|
|
|
|
}; |
57
|
15
|
|
|
|
|
50
|
$handlers = $info->{extra}{handles}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
20
|
50
|
|
|
|
47
|
DBIx::Class::Exception->throw("handles is not a hashref") |
61
|
|
|
|
|
|
|
unless Ref::Util::is_plain_hashref($handlers); |
62
|
|
|
|
|
|
|
|
63
|
20
|
|
|
|
|
70
|
foreach my $handler ( keys %$handlers ) { |
64
|
45
|
50
|
|
|
|
2983
|
next unless $handler; |
65
|
45
|
50
|
|
|
|
94
|
my $value = $handlers->{$handler} or next; |
66
|
|
|
|
|
|
|
|
67
|
45
|
|
|
|
|
98
|
my $method = "${class}::${handler}"; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Keep track of what we've installed, and don't complain about |
70
|
|
|
|
|
|
|
# being asked to reinstall it. This is needed when using |
71
|
|
|
|
|
|
|
# DBIx::Class::Schema::Loader. In theory we should check whether |
72
|
|
|
|
|
|
|
# the current method is the one we installed, and throw anyway if |
73
|
|
|
|
|
|
|
# it isn't, but this seems adequate. |
74
|
|
|
|
|
|
|
DBIx::Class::Exception->throw("${method} is already defined") |
75
|
45
|
50
|
66
|
|
|
671
|
if $self->can($method) && !$MINE{$method}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $code = |
78
|
|
|
|
|
|
|
$info->{is_nullable} |
79
|
45
|
100
|
|
|
|
162
|
? qq{ my \$val = \$_[0]->get_column("${col}"); } |
80
|
|
|
|
|
|
|
. qq{ defined(\$val) && \$val eq "${value}" } |
81
|
|
|
|
|
|
|
: qq{ \$_[0]->get_column("${col}") eq "${value}" }; |
82
|
|
|
|
|
|
|
|
83
|
45
|
|
|
|
|
104
|
$MINE{$method} = 1; |
84
|
45
|
|
|
|
|
105
|
Sub::Quote::quote_sub $method, $code; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
8
|
|
|
|
|
45
|
return $self; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |