| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
128430
|
use 5.008003; |
|
|
1
|
|
|
|
|
4
|
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
55
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package LINQ::Database; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
|
8
|
|
|
|
|
|
|
our $VERSION = '0.000_001'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
542
|
use Class::Tiny qw( dbh ); |
|
|
1
|
|
|
|
|
1839
|
|
|
|
1
|
|
|
|
|
5
|
|
|
11
|
1
|
|
|
1
|
|
268
|
use Scalar::Util (); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
336
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub BUILDARGS { |
|
14
|
1
|
|
|
1
|
0
|
179
|
my ( $self ) = ( shift ); |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
50
|
33
|
|
|
8
|
if ( @_ == 1 and Scalar::Util::blessed( $_[0] ) ) { |
|
17
|
0
|
|
|
|
|
0
|
return { dbh => $_[0] }; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
else { |
|
20
|
1
|
|
|
|
|
1615
|
require DBI; |
|
21
|
1
|
|
|
|
|
17987
|
return { dbh => 'DBI'->connect( @_ ) }; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub table { |
|
26
|
3
|
|
|
3
|
0
|
19293
|
my ( $self ) = ( shift ); |
|
27
|
3
|
|
|
|
|
7
|
my %args; |
|
28
|
3
|
50
|
33
|
|
|
50
|
if ( @_ == 1 and ref($_[0]) eq 'HASH' ) { |
|
|
|
50
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
%args = %{ $_[0] }; |
|
|
0
|
|
|
|
|
0
|
|
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
elsif ( @_ % 2 == 1 ) { |
|
32
|
3
|
|
|
|
|
13
|
%args = ( name => @_ ); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
else { |
|
35
|
0
|
|
|
|
|
0
|
%args = @_; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
529
|
require LINQ::Database::Table; |
|
39
|
3
|
|
|
|
|
22
|
'LINQ::Database::Table'->new( { database => $self, %args } ); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub prepare { |
|
43
|
3
|
|
|
3
|
0
|
88
|
my ( $self, $sql ) = ( shift, @_ ); |
|
44
|
3
|
|
|
|
|
8
|
$self->{last_sql} = $sql; |
|
45
|
3
|
|
|
|
|
49
|
$self->dbh->prepare( $sql ); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub quote { |
|
49
|
0
|
|
|
0
|
0
|
0
|
my ( $self ) = ( shift ); |
|
50
|
0
|
|
|
|
|
0
|
$self->dbh->quote( @_ ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub quote_identifier { |
|
54
|
2
|
|
|
2
|
0
|
13
|
my ( $self ) = ( shift ); |
|
55
|
2
|
|
|
|
|
81
|
$self->dbh->quote_identifier( @_ ); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=encoding utf-8 |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
LINQ::Database - LINQ extension for working with databases |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use LINQ; |
|
73
|
|
|
|
|
|
|
use LINQ::Util -all; |
|
74
|
|
|
|
|
|
|
use LINQ::Database; |
|
75
|
|
|
|
|
|
|
use DBI; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $db = 'LINQ::Database'->new( 'DBI'->connect( ... ) ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$db |
|
80
|
|
|
|
|
|
|
->table( 'pet' ) |
|
81
|
|
|
|
|
|
|
->where( check_fields 'name', -like => 'P%', -nocase ) |
|
82
|
|
|
|
|
|
|
->select( fields 'name', 'species' ) |
|
83
|
|
|
|
|
|
|
->foreach( sub { |
|
84
|
|
|
|
|
|
|
printf( "%s is a %s\n", $_->name, $_->species ); |
|
85
|
|
|
|
|
|
|
} ); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L<LINQ::Database> provides a L<LINQ::Collection>-compatible interface for |
|
90
|
|
|
|
|
|
|
accessing SQL databases. It's basically B<< DLinq for Perl >>. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 BUGS |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Please report any bugs to |
|
95
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ-Database>. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L<LINQ>. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Toby Inkster. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
110
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
|
115
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
|
116
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|
117
|
|
|
|
|
|
|
|