File Coverage

blib/lib/DBIx/DataModel/Schema/ResultAs/Subquery.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 8 50.0
condition n/a
subroutine 8 8 100.0
pod 1 2 50.0
total 42 47 89.3


line stmt bran cond sub pod time code
1             #----------------------------------------------------------------------
2             package DBIx::DataModel::Schema::ResultAs::Subquery;
3             #----------------------------------------------------------------------
4 3     3   3603 use warnings;
  3         6  
  3         298  
5 3     3   20 use strict;
  3         6  
  3         93  
6 3     3   16 use DBIx::DataModel::Carp;
  3         7  
  3         29  
7 3     3   169 use DBIx::DataModel::Statement ();
  3         7  
  3         84  
8              
9 3     3   22 use parent 'DBIx::DataModel::Schema::ResultAs';
  3         6  
  3         24  
10              
11 3     3   297 use namespace::clean;
  3         6  
  3         30  
12              
13              
14             sub new {
15 3     3 0 232 my ($class, $alias, @other) = @_;
16              
17 3 50       18 ! @other or croak "-result_as => [subquery => ...] ... too many arguments";
18              
19 3         9 my $self = {alias => $alias};
20 3         12 return bless $self, $class;
21             }
22              
23              
24              
25             sub get_result {
26 3     3 1 8 my ($self, $statement) = @_;
27              
28 3         18 $statement->_forbid_callbacks(__PACKAGE__);
29              
30 3 50       58 my @sqlize_args = $self->{alias} ? (-as => $self->{alias}) : ();
31 3 50       14 $statement->sqlize(@sqlize_args) if $statement->status < DBIx::DataModel::Statement::SQLIZED;
32              
33 3         15 my ($sql, @bind) = $statement->sql;
34              
35             # make sure the $sql is in parenthesis
36 3 50       18 $sql = "($sql)" if $sql !~ /^\(/;
37              
38 3         66 return \ [$sql, @bind]; # ref to an arrayref with SQL and bind values
39             }
40              
41             1;
42              
43             __END__