line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Meta::Role::FromSelect; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
6838
|
use strict; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
393
|
|
4
|
10
|
|
|
10
|
|
59
|
use warnings; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
388
|
|
5
|
10
|
|
|
10
|
|
56
|
use namespace::autoclean; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
107
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
953
|
use Fey::ORM::Types qw( Bool CodeRef ); |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
109
|
|
10
|
10
|
|
|
10
|
|
51728
|
use Moose::Util::TypeConstraints qw( find_type_constraint ); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
134
|
|
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
10
|
|
4170
|
use Moose::Role; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
87
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has select => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
does => 'Fey::Role::SQL::ReturnsData', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has bind_params => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => CodeRef, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has is_multi_column => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => Bool, |
28
|
|
|
|
|
|
|
default => 0, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
32
|
|
|
|
|
|
|
sub _make_sub_from_select { |
33
|
0
|
|
|
0
|
|
|
my $class = shift; |
34
|
0
|
|
|
|
|
|
my $select = shift; |
35
|
0
|
|
|
|
|
|
my $bind_sub = shift; |
36
|
0
|
|
|
|
|
|
my $is_multi_col = shift; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
0
|
|
|
|
die 'The select parameter must be do the Fey::Role::SQL::ReturnsData role' |
|
|
|
0
|
|
|
|
|
39
|
|
|
|
|
|
|
unless blessed $select |
40
|
|
|
|
|
|
|
&& $select->can('does') |
41
|
|
|
|
|
|
|
&& $select->does('Fey::Role::SQL::ReturnsData'); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if (@_) { |
44
|
0
|
|
|
|
|
|
return $class->_make_default_from_select_with_type( |
45
|
|
|
|
|
|
|
$select, |
46
|
|
|
|
|
|
|
$bind_sub, |
47
|
|
|
|
|
|
|
$is_multi_col, |
48
|
|
|
|
|
|
|
shift, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
0
|
|
|
|
|
|
return $class->_make_default_from_select_without_type( |
53
|
|
|
|
|
|
|
$select, |
54
|
|
|
|
|
|
|
$bind_sub, |
55
|
|
|
|
|
|
|
$is_multi_col |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
## use critic |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _make_default_from_select_with_type { |
62
|
0
|
|
|
0
|
|
|
my $class = shift; |
63
|
0
|
|
|
|
|
|
my $select = shift; |
64
|
0
|
|
|
|
|
|
my $bind_sub = shift; |
65
|
0
|
|
|
|
|
|
my $is_multi_col = shift; |
66
|
0
|
|
|
|
|
|
my $type = shift; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $wantarray = 0; |
69
|
0
|
0
|
0
|
|
|
|
$wantarray = 1 |
70
|
|
|
|
|
|
|
if defined $type |
71
|
|
|
|
|
|
|
&& find_type_constraint($type)->is_a_type_of('ArrayRef'); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
my $select_meth |
74
|
|
|
|
|
|
|
= $is_multi_col ? 'selectall_arrayref' : 'selectcol_arrayref'; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return sub { |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $dbh = $self->_dbh($select); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my @select_p = ( |
82
|
|
|
|
|
|
|
$select->sql($dbh), {}, |
83
|
|
|
|
|
|
|
$bind_sub ? $self->$bind_sub() : (), |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
my $return = $dbh->$select_meth(@select_p) |
87
|
|
|
|
|
|
|
or return; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
return $wantarray ? $return : $return->[0]; |
90
|
0
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _make_default_from_select_without_type { |
94
|
0
|
|
|
0
|
|
|
my $class = shift; |
95
|
0
|
|
|
|
|
|
my $select = shift; |
96
|
0
|
|
|
|
|
|
my $bind_sub = shift; |
97
|
0
|
|
|
|
|
|
my $is_multi_col = shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
my $select_meth |
100
|
|
|
|
|
|
|
= $is_multi_col ? 'selectall_arrayref' : 'selectcol_arrayref'; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
return sub { |
103
|
0
|
|
|
0
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $dbh = $self->_dbh($select); |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
my @select_p = ( |
108
|
|
|
|
|
|
|
$select->sql($dbh), {}, |
109
|
|
|
|
|
|
|
$bind_sub ? $self->$bind_sub() : (), |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
my $return = $dbh->$select_meth(@select_p) |
113
|
|
|
|
|
|
|
or return; |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
return wantarray ? @{$return} : $return->[0]; |
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |