line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Plugin::TO_JSON; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Required inclusions. |
5
|
|
|
|
|
|
|
############################################################################### |
6
|
1
|
|
|
1
|
|
198804
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
############################################################################### |
10
|
|
|
|
|
|
|
# Export our methods. |
11
|
|
|
|
|
|
|
############################################################################### |
12
|
1
|
|
|
1
|
|
6
|
use base qw( Exporter ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
282
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw( |
14
|
|
|
|
|
|
|
TO_JSON |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
############################################################################### |
18
|
|
|
|
|
|
|
# Version number. |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
############################################################################### |
23
|
|
|
|
|
|
|
# Subroutine: TO_JSON() |
24
|
|
|
|
|
|
|
############################################################################### |
25
|
|
|
|
|
|
|
# Turns the CDBI data record into a HASHREF suitable for use with 'JSON::XS' |
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
sub TO_JSON { |
28
|
1
|
|
|
1
|
1
|
84259
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# get all of our data |
31
|
1
|
|
|
|
|
5
|
my @cols = $self->columns(); |
32
|
1
|
|
|
|
|
74
|
my %data; |
33
|
1
|
|
|
|
|
5
|
@data{@cols} = $self->get(@cols); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# deflate the data, giving us JUST a hash of the raw data |
36
|
1
|
|
|
|
|
321
|
foreach my $column (@cols) { |
37
|
3
|
|
|
|
|
430
|
my $name = $column->name(); |
38
|
3
|
|
|
|
|
24
|
$data{$name} = $self->_deflated_column($column, $data{$name}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# return the data back to the caller. |
42
|
1
|
|
|
|
|
19
|
return \%data; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Class::DBI::Plugin::TO_JSON - Help integrate Class::DBI with JSON::XS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package MY::DB; |
54
|
|
|
|
|
|
|
use base qw(Class::DBI); |
55
|
|
|
|
|
|
|
use Class::DBI::Plugin::TO_JSON; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
C helps integrate C with C, |
60
|
|
|
|
|
|
|
by implementing a C method which turns your data record into a |
61
|
|
|
|
|
|
|
plain/raw HASHREF with no inflated values. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 METHODS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=over |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item TO_JSON() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Turns the C data record into a HASHREF suitable for use with |
70
|
|
|
|
|
|
|
C |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 AUTHOR |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Graham TerMarsch (cpan@howlingfrog.com) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 COPYRIGHT |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Copyright (C) 2008, Graham TerMarsch. All rights reserved. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the same |
83
|
|
|
|
|
|
|
terms as Perl itself. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SEE ALSO |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L, |
88
|
|
|
|
|
|
|
L. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |