Database.pm

filter: Statementstmt 84.2% 32 / 38 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 5 totaltotal 66.6% 46 / 69 SCAR 18.9
CC
6
Cov
74%
table
5.3
BUILDARGS
3.6
quote
2.0
CRAP 6.6
« Database/Table.pm ↑ Summary
1 1 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package LINQ::Database;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.000_001';
9  
10 1 ▶use Class::Tiny qw( dbh );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub BUILDARGS {
14 1 ▶ my ( $self ) = ( shift );
Subroutine BUILDARGS: called CC=3 SCAR=12.7
Pod undocumented
15
16 1 ▶ if ( @_ == 1 and Scalar::Util::blessed( $_[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and builtin::blessed($_[0])) { } 0 1 1
Condition33%1/3
@_ == 1 and builtin::blessed($_[0])
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and builtin::blessed($_[0])
@_ == 1 builtin::blessed($_[0])
Truth table33%1/3
A and B
A= @_ == 1B= builtin::blessed($_[0])
ABresult
0X0
100
111
17 0 return { dbh => $_[0] };
18 }
19 else {
20 1 require DBI;
21 1 return { dbh => 'DBI'->connect( @_ ) };
22 }
23 }
24  
25 sub table {
26 3 ▶ my ( $self ) = ( shift );
Subroutine table: called CC=4 SCAR=16.8
Pod undocumented
27 3 my %args;
28 3 ▶ if ( @_ == 1 and ref($_[0]) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 3 3
elsif (@_ % 2 == 1) { } 3 0 3
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
030
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
29 0 %args = %{ $_[0] };
30 }
31 elsif ( @_ % 2 == 1 ) {
32 3 %args = ( name => @_ );
33 }
34 else {
35 0 %args = @_;
36 }
37
38 3 require LINQ::Database::Table;
39 3 'LINQ::Database::Table'->new( { database => $self, %args } );
40 }
41  
42 sub prepare {
43 3 ▶ my ( $self, $sql ) = ( shift, @_ );
Subroutine prepare: called CC=1 SCAR=0.0
Pod undocumented
44 3 $self->{last_sql} = $sql;
45 3 $self->dbh->prepare( $sql );
46 }
47  
48 sub quote {
49 0 ▶ my ( $self ) = ( shift );
Subroutine quote: not called CC=1 SCAR=6.9
Pod undocumented
50 0 $self->dbh->quote( @_ );
51 }
52  
53 sub quote_identifier {
54 2 ▶ my ( $self ) = ( shift );
Subroutine quote_identifier: called CC=1 SCAR=0.0
Pod undocumented
55 2 $self->dbh->quote_identifier( @_ );
56 }
57  
58 1 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  
« Database/Table.pm ↑ Summary