| 1 | package Fey::SQL::Delete; | ||||||||||
| 2 | |||||||||||
| 3 | 26 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 26 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 26 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 26 | our $VERSION = '0.43'; | |||||||||
| 8 | |||||||||||
| 9 | 26 | ▶ | use Fey::Types qw( ArrayRef CanQuote Table ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 26 | ▶ | use Scalar::Util qw( blessed ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 26 | ▶ | use Moose 2.1200; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 26 | ▶ | use MooseX::Params::Validate 0.21 qw( pos_validated_list ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 26 | ▶ | use MooseX::SemiAffordanceAccessor 0.03; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 26 | ▶ | use MooseX::StrictConstructor 0.13; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 26 | with 'Fey::Role::SQL::HasWhereClause', | |||||||||
| 18 | 'Fey::Role::SQL::HasOrderByClause', | ||||||||||
| 19 | 'Fey::Role::SQL::HasLimitClause'; | ||||||||||
| 20 | |||||||||||
| 21 | 26 | with 'Fey::Role::SQL::HasBindParams' => { -excludes => 'bind_params' }; | |||||||||
| 22 | |||||||||||
| 23 | has '_from' => ( | ||||||||||
| 24 | is => 'rw', | ||||||||||
| 25 | isa => ArrayRef, | ||||||||||
| 26 | 6 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 26 | init_arg => undef, | |||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 26 | with 'Fey::Role::SQL::Cloneable'; | |||||||||
| 31 | |||||||||||
| 32 | 6 | ▶ | sub delete { return $_[0] } | ||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | |||||||||||
| 34 | sub from { | ||||||||||
| 35 | 6 | ▶ | my $self = shift; | ||||||||
|
Subroutine
from: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 36 | |||||||||||
| 37 | 6 | ▶ | my $count = @_ ? @_ : 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 6 | my (@tables) = pos_validated_list( | |||||||||
| 39 | \@_, | ||||||||||
| 40 | ( ( { isa => Table } ) x $count ), | ||||||||||
| 41 | MX_PARAMS_VALIDATE_NO_CACHE => 1, | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | 5 | $self->_set_from( \@tables ); | |||||||||
| 45 | |||||||||||
| 46 | 5 | return $self; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | sub sql { | ||||||||||
| 50 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
sql: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | 3 | my ($dbh) = pos_validated_list( \@_, { isa => CanQuote } ); | |||||||||
| 52 | |||||||||||
| 53 | return ( | ||||||||||
| 54 | 3 | join ' ', | |||||||||
| 55 | $self->delete_clause($dbh), | ||||||||||
| 56 | $self->where_clause($dbh), | ||||||||||
| 57 | $self->order_by_clause($dbh), | ||||||||||
| 58 | $self->limit_clause($dbh), | ||||||||||
| 59 | ); | ||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | sub delete_clause { | ||||||||||
| 63 | 5 | ▶ | return 'DELETE FROM ' . $_[0]->_tables_subclause( $_[1] ); | ||||||||
|
Subroutine
delete_clause: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub _tables_subclause { | ||||||||||
| 67 | return ( | ||||||||||
| 68 | join ', ', | ||||||||||
| 69 | 5 | ▶ | map { $_[1]->quote_identifier( $_->name() ) } @{ $_[0]->_from() } | ||||||||
|
Subroutine
_tables_subclause: called CC=1 SCAR=0.0
| |||||||||||
| 70 | ); | ||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 26 | __PACKAGE__->meta()->make_immutable(); | |||||||||
| 74 | |||||||||||
| 75 | 26 | 1; | |||||||||
| 76 | |||||||||||
| 77 | # ABSTRACT: Represents a DELETE query | ||||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||
| 80 | |||||||||||
| 81 | =pod | ||||||||||
| 82 | |||||||||||
| 83 | =head1 NAME | ||||||||||
| 84 | |||||||||||
| 85 | Fey::SQL::Delete - Represents a DELETE query | ||||||||||
| 86 | |||||||||||
| 87 | =head1 VERSION | ||||||||||
| 88 | |||||||||||
| 89 | version 0.43 | ||||||||||
| 90 | |||||||||||
| 91 | =head1 SYNOPSIS | ||||||||||
| 92 | |||||||||||
| 93 | my $sql = Fey::SQL->new_delete(); | ||||||||||
| 94 | |||||||||||
| 95 | # DELETE FROM Part | ||||||||||
| 96 | # WHERE Part.name LIKE '%Widget' | ||||||||||
| 97 | $sql->delete(); | ||||||||||
| 98 | $sql->from($Part); | ||||||||||
| 99 | $sql->where( $name, 'LIKE', '%Widget' ); | ||||||||||
| 100 | |||||||||||
| 101 | print $sql->sql($dbh); | ||||||||||
| 102 | |||||||||||
| 103 | =head1 DESCRIPTION | ||||||||||
| 104 | |||||||||||
| 105 | This class represents a C<DELETE> query. | ||||||||||
| 106 | |||||||||||
| 107 | =head1 METHODS | ||||||||||
| 108 | |||||||||||
| 109 | This class provides the following methods: | ||||||||||
| 110 | |||||||||||
| 111 | =head2 Constructor | ||||||||||
| 112 | |||||||||||
| 113 | To construct an object of this class, call C<< $query->delete() >> on | ||||||||||
| 114 | a C<Fey::SQL> object. | ||||||||||
| 115 | |||||||||||
| 116 | =head2 $delete->delete() | ||||||||||
| 117 | |||||||||||
| 118 | This method is basically a no-op that exists to so that L<Fey::SQL> | ||||||||||
| 119 | has something to call after it constructs an object in this class. | ||||||||||
| 120 | |||||||||||
| 121 | =head2 $delete->from(...) | ||||||||||
| 122 | |||||||||||
| 123 | This method specifies the C<FROM> clause of the query. It expects one | ||||||||||
| 124 | or more L<Fey::Table> objects (not aliases). Most RDBMS | ||||||||||
| 125 | implementations only allow for a single table here, but some (like | ||||||||||
| 126 | MySQL) do allow for multi-table deletes. | ||||||||||
| 127 | |||||||||||
| 128 | =head2 $delete->where(...) | ||||||||||
| 129 | |||||||||||
| 130 | See the L<Fey::SQL section on WHERE Clauses|Fey::SQL/WHERE Clauses> | ||||||||||
| 131 | for more details. | ||||||||||
| 132 | |||||||||||
| 133 | =head2 $delete->order_by(...) | ||||||||||
| 134 | |||||||||||
| 135 | See the L<Fey::SQL section on ORDER BY Clauses|Fey::SQL/ORDER BY | ||||||||||
| 136 | Clauses> for more details. | ||||||||||
| 137 | |||||||||||
| 138 | =head2 $delete->limit(...) | ||||||||||
| 139 | |||||||||||
| 140 | See the L<Fey::SQL section on LIMIT Clauses|Fey::SQL/LIMIT Clauses> | ||||||||||
| 141 | for more details. | ||||||||||
| 142 | |||||||||||
| 143 | =head2 $delete->sql() | ||||||||||
| 144 | |||||||||||
| 145 | Returns the full SQL statement which this object represents. A DBI | ||||||||||
| 146 | handle must be passed so that identifiers can be properly quoted. | ||||||||||
| 147 | |||||||||||
| 148 | =head2 $delete->bind_params() | ||||||||||
| 149 | |||||||||||
| 150 | See the L<Fey::SQL section on Bind Parameters|Fey::SQL/Bind | ||||||||||
| 151 | Parameters> for more details. | ||||||||||
| 152 | |||||||||||
| 153 | =head2 $delete->delete_clause() | ||||||||||
| 154 | |||||||||||
| 155 | Returns the C<DELETE> clause portion of the SQL statement as a string. | ||||||||||
| 156 | |||||||||||
| 157 | =head2 $delete->where_clause() | ||||||||||
| 158 | |||||||||||
| 159 | Returns the C<WHERE> clause portion of the SQL statement as a string. | ||||||||||
| 160 | |||||||||||
| 161 | =head2 $delete->order_by_clause() | ||||||||||
| 162 | |||||||||||
| 163 | Returns the C<ORDER BY> clause portion of the SQL statement as a | ||||||||||
| 164 | string. | ||||||||||
| 165 | |||||||||||
| 166 | =head2 $delete->limit_clause() | ||||||||||
| 167 | |||||||||||
| 168 | Returns the C<LIMIT> clause portion of the SQL statement as a string. | ||||||||||
| 169 | |||||||||||
| 170 | =head1 ROLES | ||||||||||
| 171 | |||||||||||
| 172 | =over 4 | ||||||||||
| 173 | |||||||||||
| 174 | =item * L<Fey::Role::SQL::HasBindParams> | ||||||||||
| 175 | |||||||||||
| 176 | =item * L<Fey::Role::SQL::HasWhereClause> | ||||||||||
| 177 | |||||||||||
| 178 | =item * L<Fey::Role::SQL::HasOrderByClause> | ||||||||||
| 179 | |||||||||||
| 180 | =item * L<Fey::Role::SQL::HasLimitClause> | ||||||||||
| 181 | |||||||||||
| 182 | =item * L<Fey::Role::SQL::Cloneable> | ||||||||||
| 183 | |||||||||||
| 184 | =back | ||||||||||
| 185 | |||||||||||
| 186 | =head1 BUGS | ||||||||||
| 187 | |||||||||||
| 188 | See L<Fey> for details on how to report bugs. | ||||||||||
| 189 | |||||||||||
| 190 | =head1 AUTHOR | ||||||||||
| 191 | |||||||||||
| 192 | Dave Rolsky <autarch@urth.org> | ||||||||||
| 193 | |||||||||||
| 194 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 195 | |||||||||||
| 196 | This software is Copyright (c) 2011 - 2015 by Dave Rolsky. | ||||||||||
| 197 | |||||||||||
| 198 | This is free software, licensed under: | ||||||||||
| 199 | |||||||||||
| 200 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 201 | |||||||||||
| 202 | =cut | ||||||||||