File Coverage

blib/lib/DBomb/Meta/Key.pm
Criterion Covered Total %
statement 15 49 30.6
branch 0 4 0.0
condition n/a
subroutine 5 12 41.6
pod 0 7 0.0
total 20 72 27.7


line stmt bran cond sub pod time code
1             package DBomb::Meta::Key;
2              
3             =head1 NAME
4              
5             DBomb::Meta::Key - An vector of columns.
6              
7             =head1 SYNOPSIS
8              
9             =cut
10              
11 1     1   1092 use strict;
  1         3  
  1         41  
12 1     1   6 use warnings;
  1         2  
  1         45  
13             our $VERSION = '$Revision: 1.13 $';
14              
15 1     1   955 use Tie::IxHash;
  1         13995  
  1         34  
16 1     1   9 use Carp::Assert;
  1         1  
  1         17  
17             use Class::MethodMaker
18 1         13 'new_with_init' => 'new',
19             'get_set' => [qw(columns)], # IxHash{ column_name => column_info }
20             'boolean' => [qw(is_pk)],
21 1     1   214 ;
  1         3  
22              
23             ## init( $cols_list, $opts)
24             sub init
25             {
26 0     0 0   my ($self, $cols_list, $opts) = @_;
27 0           my %h;
28 0           tie %h, 'Tie::IxHash';
29 0           $self->columns(\%h);
30              
31 0 0         $cols_list = [$cols_list] if ref($cols_list) ne 'ARRAY';
32 0           for my $cinfo (@$cols_list){
33 0           $self->columns->{$cinfo->name} = $cinfo;
34             }
35              
36             ## Register with table info
37 0           push @{$self->table_info->keys}, $self;
  0            
38             }
39              
40             sub table_info
41             {
42 0     0 0   my $self = shift;
43 0           assert(@_ == 0);
44 0           tied(%{$self->columns})->Values(0)->table_info;
  0            
45             }
46              
47             sub columns_list
48             {
49 0     0 0   my $self = shift;
50 0           assert(@_ == 0);
51 0           [values %{$self->columns}]
  0            
52             }
53              
54             sub column_names
55             {
56 0     0 0   my $self = shift;
57 0           assert(@_ == 0);
58 0           [keys %{$self->columns}]
  0            
59             }
60              
61             sub column_count
62             {
63 0     0 0   my $self = shift;
64 0           assert(@_ == 0);
65 0           tied(%{$self->columns})->Length;
  0            
66             }
67              
68             sub resolve
69             {
70             ## No action.
71 0     0 0   return 1;
72             }
73              
74             ## returns a where clause optionally with bind values
75             ## mk_where(@bind_values)
76             sub mk_where
77             {
78 0     0 0   my $self = shift;
79 0           my $where = new DBomb::Query::Expr();
80              
81 0           for (values %{$self->columns}){
  0            
82 0           $where->and(+{$_->fq_name => '?'});
83             }
84 0 0         push @{$where->bind_values}, @_ if @_;
  0            
85              
86 0           return $where;
87             }
88              
89              
90             1;
91             __END__