File Coverage

blib/lib/EntityModel/Query/Table.pm
Criterion Covered Total %
statement 14 21 66.6
branch 3 10 30.0
condition 1 3 33.3
subroutine 3 3 100.0
pod 2 2 100.0
total 23 39 58.9


line stmt bran cond sub pod time code
1             package EntityModel::Query::Table;
2             {
3             $EntityModel::Query::Table::VERSION = '0.102';
4             }
5             use EntityModel::Class {
6 16         361 '_isa' => [qw(EntityModel::Query::Base)],
7             'entity' => { type => 'EntityModel::Entity', defer => 1 },
8             'table' => 'string',
9             'alias' => 'string',
10 16     16   11227 };
  16         31  
11              
12             =head1 NAME
13              
14             EntityModel::Query::Table
15              
16             =head1 VERSION
17              
18             version 0.102
19              
20             =head1 SYNOPSIS
21              
22             See L.
23              
24             =head1 DESCRIPTION
25              
26             See L.
27              
28             =cut
29              
30             =head1 METHODS
31              
32             =cut
33              
34             =head2 new
35              
36             =cut
37              
38             sub new {
39 10     10 1 1557 my $class = shift;
40 10         33 my $self = bless { }, $class;
41              
42             # Handle plain value
43 10 50 33     72 if(@_ == 1 && !ref $_[0]) {
44 10         56 $self->table($_[0]);
45             } else {
46 0         0 $self->entity($_[0]);
47             }
48              
49 10         138 return $self;
50             }
51              
52             =head2 asString
53              
54             =cut
55              
56             sub asString {
57 20     20 1 26 my $self = shift;
58 20         33 my $str = '';
59 20 50       53 if($self->table) {
60 20         121 $str = $self->table;
61             } else {
62 0 0       0 return $self->entity unless ref($self->entity);
63 0 0       0 if(ref $self->entity eq 'HASH') {
64 0         0 my ($alias, $t) = %{$self->entity};
  0         0  
65 0         0 return "$t as $alias";
66             }
67 0         0 return '"' . $self->entity->schema . '"."' . $self->entity->name . '"';
68             }
69 20 50       117 $str .= ' as ' . $self->alias if $self->alias;
70 20         146 return $str;
71             }
72              
73             1;
74              
75             __END__