DBomb/Meta/HasQuery.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 65 CC 3 SCAR 17.5
CC
3
Cov
0%
resolve
12.0
init
2.0
BEGIN
2.0
CRAP 5.8
1 package DBomb::Meta::HasQuery;
2  
3 =head1 NAME
4  
5 DBomb::Meta::HasQuery - A column based on a Query object.
6  
7 =cut
8  
9 use strict;
10 use warnings;
11 our $VERSION = '$Revision: 1.3 $';
12  
13 use Carp::Assert;
14 use Class::MethodMaker
15 'new_with_init' => 'new',
16 'get_set' => [qw(query), ## The query object
17 qw(attr), ## The accessor
18 qw(table_info), ## tableinfo object
19 qw(f_table), ## foreign table
20 qw(bind_subs), ## [coderef, coderef,...]
21 ];
22  
23 ## new HasQuery($table, $query, [@bind_subs] $opts)
24 sub init
25 {
26 my ($self, $table, $f_table, $query, $bind_subs, $opts) = @_;
27 $opts ||= {};
28  
29 assert(5 <= @_ && @_ <= 6, 'parameter count');
30 assert(UNIVERSAL::isa($self,__PACKAGE__));
31 assert(UNIVERSAL::isa($table,'DBomb::Meta::TableInfo'), 'HasQuery requires a foreign table info');
32 assert(UNIVERSAL::isa($query,'DBomb::Query'), 'HasQuery->new requires DBomb::Query');
33 assert(UNIVERSAL::isa($bind_subs, 'ARRAY'));
34 for (@$bind_subs){
35 assert(UNIVERSAL::isa($_,'CODE'));
36 }
37 assert(UNIVERSAL::isa($opts, 'HASH'));
38  
39 $self->query($query);
40 $self->attr($opts->{'attr'} || join(q//, "_dbo_has_query: ", @{$query->column_names}, " $query"));
41 $self->table_info($table);
42 $self->f_table($f_table);
43  
44 $self->bind_subs([]);
45 for (@$bind_subs){
46 push @{$self->bind_subs}, $_
47 }
48 }
49  
50 sub resolve
51 {
52 my $self = shift;
53  
54 my $t = $self->f_table;
55 unless (UNIVERSAL::isa($t, 'DBomb::TableInfo')){
56 die "could not resolve HasQuery table_info '$t'" unless defined $self->f_table(DBomb->resolve_table_name(undef,$t));
57 }
58 return 1;
59 }
60  
61 1;
62 __END__