blib/lib/DBIx/Lookup/Field.pm

filter: Statementstmt 57.1% 20 / 35 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 54.9% 28 / 51 CC 5 SCAR 25.8
CC
5
Cov
49%
dbi_lookup_field
30.0
dbi_lookup_field_with_reverse
2.0
BEGIN
1.0
CRAP 13.2
↑ Summary
1 1 ▶use 5.008;
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 DBIx::Lookup::Field;
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $DBIx::Lookup::Field::VERSION = '2.101420';
8 }
9 # ABSTRACT: Create a lookup hash from a database table
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 our %EXPORT_TAGS = (
13 all => [ qw(dbi_lookup_field dbi_lookup_field_with_reverse) ],
14 );
15 1 our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };
16  
17 0 ▶sub dbi_lookup_field {
Subroutine dbi_lookup_field: not called CC=5 SCAR=34.0
Pod documented
18 0 my %args = @_;
19 0 my $msg = 'dbi_lookup_field: missing required argument ';
20 0 for (qw/DBH TABLE KEY VALUE/) {
21 0 ▶ $args{$_} || croak "$msg '$_'\n";
Branch: 1 branch
BranchTrueFalseTotal
$args{$_} or croak("$msg '${_}'\n") 0 0 0
22 }
23 0 ▶ my $where = $args{WHERE} ? "WHERE $args{WHERE}" : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'WHERE'} ? : 0 0 0
24 my $sth = $args{DBH}->prepare(
25 0 qq/
26 select $args{KEY}, $args{VALUE} from $args{TABLE} $where
27 /
28 );
29 0 $sth->execute;
30 0 my %lookup;
31 0 ▶ while (my ($key, $value) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
32 0 $lookup{$key} = $value;
33 }
34 0 $sth->finish;
35 0 return \%lookup;
36 }
37  
38 0 ▶sub dbi_lookup_field_with_reverse {
Subroutine dbi_lookup_field_with_reverse: not called CC=1 SCAR=6.9
Pod documented
39 0 my $lookup = dbi_lookup_field(@_);
40 0 my %reverse = reverse %$lookup;
41 0 ($lookup, \%reverse);
42 }
43 1 1;
44  
45  
46 __END__
↑ Summary