File Coverage

lib/DBIx/ActiveRecord/Arel/Query/Count.pm
Criterion Covered Total %
statement 21 21 100.0
branch 3 6 50.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 29 33 87.8


line stmt bran cond sub pod time code
1             package DBIx::ActiveRecord::Arel::Query::Count;
2 2     2   12 use strict;
  2         3  
  2         70  
3 2     2   11 use warnings;
  2         3  
  2         134  
4 2     2   11 use base 'DBIx::ActiveRecord::Arel::Query';
  2         3  
  2         519  
5              
6             sub new {
7 1     1 0 2 my ($self, $main) = @_;
8 1         7 my $o = $self->SUPER::new($main);
9 1         5 $o->merge($main->query);
10 1         3 $o;
11             }
12              
13             sub _to_sql {
14 1     1   3 my ($self) = @_;
15              
16 1 50       2 my $table = $self->has_join ? $self->main_table_with_alias : $self->main->table;
17 1         3 my $sql = 'SELECT COUNT(*) FROM '.$table;
18 1         7 my $join = $self->build_join;
19 1 50       4 $sql .= ' '.$join if $join;
20 1         6 my $where = $self->build_where;
21 1 50       7 $sql .= " WHERE $where" if $where;
22 1         2 $sql;
23             }
24              
25             1;