line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FeyX::Active::SQL; |
2
|
1
|
|
|
1
|
|
7605
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'dbh' => ( |
8
|
|
|
|
|
|
|
is => 'ro', |
9
|
|
|
|
|
|
|
isa => 'DBI::db', |
10
|
|
|
|
|
|
|
required => 1, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'execute_rv' => (is => 'rw', isa => 'Any'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub prepare_sql { (shift)->sql } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub prepare { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
$self->dbh->prepare( $self->prepare_sql ); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub execute { |
23
|
|
|
|
|
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
my $sth = $self->prepare; |
25
|
|
|
|
|
|
|
# NOTE: |
26
|
|
|
|
|
|
|
# this is because of some silly Moose bug |
27
|
|
|
|
|
|
|
# and the fact that dave uses those silly |
28
|
|
|
|
|
|
|
# semiaffordance accessors. |
29
|
|
|
|
|
|
|
# * sigh * |
30
|
|
|
|
|
|
|
# - SL |
31
|
|
|
|
|
|
|
if ($self->can('set_execute_rv')) { |
32
|
|
|
|
|
|
|
$self->set_execute_rv( $sth->execute( $self->bind_params ) ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
|
|
|
|
|
|
$self->execute_rv( $sth->execute( $self->bind_params ) ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
$sth; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
around sql => sub { |
41
|
|
|
|
|
|
|
my $next = shift; |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
$self->$next( $self->dbh ); |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
no Moose::Role; 1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
FeyX::Active::SQL - A role to represent an active SQL statement |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This is a role that all the FeyX::Active::SQL::* objects consume, |
59
|
|
|
|
|
|
|
it contains all the basic logic to manage and execute the SQL |
60
|
|
|
|
|
|
|
commands. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item B<dbh> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This is a L<DBI> database handle. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item B<execute_rv> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This is the return value of C<execute> on |
73
|
|
|
|
|
|
|
the given L<DBI> statement handle in our |
74
|
|
|
|
|
|
|
C<execute> method. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 METHODS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=over 4 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item B<prepare_sql> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This simply calls C<sql> to get the SQL code that L<Fey::SQL> |
85
|
|
|
|
|
|
|
will generate for us. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item B<prepare> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This calls C<prepare_sql> and passes that SQL to the C<prepare> |
90
|
|
|
|
|
|
|
method of our C<dbh>. It will return a L<DBI> statement handle. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item B<execute> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This will call C<prepare> to get the L<DBI> statement handle, |
95
|
|
|
|
|
|
|
then it will call C<execute> on the statement handle and pass in |
96
|
|
|
|
|
|
|
the bind params that L<Fey::SQL> will generate for us. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This will save any return value of C<execute> in the C<execute_rv> |
99
|
|
|
|
|
|
|
attribute and then return the L<DBI> statement handle. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item B<sql> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This just wraps the L<Fey::SQL> C<sql> method to make sure that |
104
|
|
|
|
|
|
|
we are passing in our C<dbh>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 BUGS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
111
|
|
|
|
|
|
|
exception. If you find a bug please either email me, or add the bug |
112
|
|
|
|
|
|
|
to cpan-RT. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Copyright 2009-2010 Infinity Interactive, Inc. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
125
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |