line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
package DBIx::DataModel::Schema::ResultAs::Hashref; |
3
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
4
|
3
|
|
|
3
|
|
2915
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
126
|
|
5
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
119
|
|
6
|
3
|
|
|
3
|
|
19
|
use Carp::Clan qw[^(DBIx::DataModel::|SQL::Abstract)]; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
32
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
367
|
use parent 'DBIx::DataModel::Schema::ResultAs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
237
|
use namespace::clean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
26
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
7
|
|
|
7
|
0
|
19
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
|
|
14
|
my $self; |
16
|
|
|
|
|
|
|
|
17
|
7
|
100
|
100
|
|
|
44
|
if ((ref $_[0] || '') eq 'CODE') { |
18
|
1
|
|
|
|
|
4
|
$self = {make_key => shift}; |
19
|
1
|
50
|
|
|
|
6
|
!@_ or croak "-result_as => [hashref => sub {...}] : improper other args after sub{}"; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
6
|
|
|
|
|
21
|
$self = {cols => \@_}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
24
|
return bless $self, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_result { |
30
|
7
|
|
|
7
|
1
|
21
|
my ($self, $statement) = @_; |
31
|
|
|
|
|
|
|
|
32
|
7
|
|
66
|
|
|
39
|
my $make_key = $self->{make_key} || do { |
33
|
|
|
|
|
|
|
my @cols = @{$self->{cols}}; |
34
|
|
|
|
|
|
|
@cols = $statement->meta_source->primary_key if !@cols; |
35
|
|
|
|
|
|
|
croak "-result_as=>'hashref' impossible: no primary key" if !@cols; |
36
|
18
|
50
|
|
18
|
|
27
|
sub {my $row = shift; map {defined $row->{$_} ? $row->{$_} : ''} @cols}; |
|
18
|
|
|
|
|
35
|
|
|
27
|
|
|
|
|
90
|
|
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
27
|
$statement->execute; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
17
|
my %hash; |
42
|
7
|
|
|
|
|
22
|
while (my $row = $statement->next) { |
43
|
21
|
|
|
|
|
51
|
my @key = $make_key->($row); |
44
|
21
|
|
|
|
|
65
|
my $last_key_item = pop @key; |
45
|
21
|
|
|
|
|
36
|
my $node = \%hash; |
46
|
21
|
|
100
|
|
|
100
|
$node = $node->{$_} ||= {} foreach @key; |
47
|
21
|
|
|
|
|
103
|
$node->{$last_key_item} = $row; |
48
|
|
|
|
|
|
|
} |
49
|
7
|
|
|
|
|
31
|
$statement->finish; |
50
|
7
|
|
|
|
|
255
|
return \%hash; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |