| 1 | package SQL::Composer::Delete; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | require Carp; | |||||||||||||||||||
| 7 | 3 | ▶ | use SQL::Composer::Quoter; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use SQL::Composer::Expression; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | sub new { | ||||||||||||||||||||
| 11 | 6 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||
| 12 | 6 | my (%params) = @_; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 6 | my $self = { table => $params{from} }; | |||||||||||||||||||
| 15 | 6 | bless $self, $class; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | $self->{quoter} = | ||||||||||||||||||||
| 18 | 6 | ▶ | $params{quoter} || SQL::Composer::Quoter->new(driver => $params{driver}); | ||||||||||||||||||
|
Condition33%1/3
$params{'quoter'} || 'SQL::Composer::Quoter'->new('driver', $params{'driver'})
MC/DC0%0/2
$params{'quoter'} || 'SQL::Composer::Quoter'->new('driver', $params{'driver'})
$params{'quoter'}
'SQL::Composer::Quoter'->new('driver', $params{'driver'})
Truth table33%1/3
A || B
A= $params{'quoter'}B= 'SQL::Composer::Quoter'->new('driver', $params{'driver'})
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 6 | my $sql = ''; | |||||||||||||||||||
| 21 | 6 | my @bind; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 6 | $sql .= 'DELETE FROM '; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 6 | $sql .= $self->_quote($params{from}); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 6 | ▶ | if ($params{where}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | my $expr = SQL::Composer::Expression->new( | ||||||||||||||||||||
| 29 | quoter => $self->{quoter}, | ||||||||||||||||||||
| 30 | expr => $params{where} | ||||||||||||||||||||
| 31 | 1 | ); | |||||||||||||||||||
| 32 | 1 | $sql .= ' WHERE ' . $expr->to_sql; | |||||||||||||||||||
| 33 | 1 | push @bind, $expr->to_bind; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 6 | ▶ | if (defined(my $limit = $params{limit})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 2 | $sql .= ' LIMIT ' . $limit; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 6 | ▶ | if (defined(my $offset = $params{offset})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 1 | $sql .= ' OFFSET ' . $offset; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 6 | $self->{sql} = $sql; | |||||||||||||||||||
| 45 | 6 | $self->{bind} = \@bind; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 6 | return $self; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2 | ▶ | sub table { shift->{table} } | ||||||||||||||||||
|
Subroutine
table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 5 | ▶ | sub to_sql { shift->{sql} } | ||||||||||||||||||
|
Subroutine
to_sql: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 53 | 5 | ▶ | sub to_bind { @{shift->{bind} || []} } | ||||||||||||||||||
|
Subroutine
to_bind: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | sub _quote { | ||||||||||||||||||||
| 56 | 6 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_quote: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 6 | my ($column) = @_; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 6 | return $self->{quoter}->quote($column); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 3 | 1; | |||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||