| 1 | package SQL::Translator::Schema::Trigger; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | SQL::Translator::Schema::Trigger - SQL::Translator trigger object | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | use SQL::Translator::Schema::Trigger; | ||||||||||||||||||||||||||||
| 12 | my $trigger = SQL::Translator::Schema::Trigger->new( | ||||||||||||||||||||||||||||
| 13 | name => 'foo', | ||||||||||||||||||||||||||||
| 14 | perform_action_when => 'before', # or after | ||||||||||||||||||||||||||||
| 15 | database_events => [qw/update insert/], # also update, update_on, delete | ||||||||||||||||||||||||||||
| 16 | fields => [], # if event is "update" | ||||||||||||||||||||||||||||
| 17 | on_table => 'foo', # table name | ||||||||||||||||||||||||||||
| 18 | action => '...', # text of trigger | ||||||||||||||||||||||||||||
| 19 | schema => $schema, # Schema object | ||||||||||||||||||||||||||||
| 20 | scope => 'row', # or statement | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | C<SQL::Translator::Schema::Trigger> is the trigger object. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 METHODS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 70 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 70 | ▶ | use SQL::Translator::Utils qw(parse_list_arg ex2err throw uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 70 | ▶ | use SQL::Translator::Types qw(schema_obj enum); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 70 | ▶ | use Sub::Quote qw(quote_sub); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 70 | extends 'SQL::Translator::Schema::Object'; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 70 | our $VERSION = '1.6_3'; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 new | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Object constructor. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | my $schema = SQL::Translator::Schema::Trigger->new; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 49 | 70 | ▶ | my ($orig, $self, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 50 | 70 | my $args = $self->$orig(@args); | |||||||||||||||||||||||||||
| 51 | 70 | ▶ | if (exists $args->{on_table}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 65 | my $arg = delete $args->{on_table}; | |||||||||||||||||||||||||||
| 53 | 65 | ▶ | my $table = $args->{schema}->get_table($arg) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | or die "Table named $arg doesn't exist"; | ||||||||||||||||||||||||||||
| 55 | 65 | $args->{table} = $table; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 70 | ▶ | if (exists $args->{database_event}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 13 | $args->{database_events} = delete $args->{database_event}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 70 | return $args; | |||||||||||||||||||||||||||
| 61 | 70 | }; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 perform_action_when | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Gets or sets whether the event happens "before" or "after" the | ||||||||||||||||||||||||||||
| 66 | C<database_event>. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | $trigger->perform_action_when('after'); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 70 | has perform_action_when => ( | |||||||||||||||||||||||||||
| 73 | is => 'rw', | ||||||||||||||||||||||||||||
| 74 | coerce => quote_sub(q{ defined $_[0] ? lc $_[0] : $_[0] }), | ||||||||||||||||||||||||||||
| 75 | isa => enum([qw(before after)], { | ||||||||||||||||||||||||||||
| 76 | msg => "Invalid argument '%s' to perform_action_when", | ||||||||||||||||||||||||||||
| 77 | allow_undef => 1, | ||||||||||||||||||||||||||||
| 78 | }), | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 70 | around perform_action_when => \&ex2err; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub database_event { | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =pod | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 database_event | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Obsolete please use database_events! | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
database_event: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 2 | return $self->database_events( @_ ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 database_events | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Gets or sets the events that triggers the trigger. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | my $ok = $trigger->database_events('insert'); | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | has database_events => ( | ||||||||||||||||||||||||||||
| 107 | is => 'rw', | ||||||||||||||||||||||||||||
| 108 | coerce => quote_sub(q{ [ map { lc } ref $_[0] eq 'ARRAY' ? @{$_[0]} : ($_[0]) ] }), | ||||||||||||||||||||||||||||
| 109 | isa => sub { | ||||||||||||||||||||||||||||
| 110 | 71 | ▶ | my @args = @{$_[0]}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 111 | 71 | my %valid = map { $_, 1 } qw[ insert update update_on delete ]; | |||||||||||||||||||||||||||
| 112 | 71 | my @invalid = grep { !defined $valid{ $_ } } @args; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 71 | ▶ | if ( @invalid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 1 | throw( | |||||||||||||||||||||||||||
| 116 | sprintf("Invalid events '%s' in database_events", | ||||||||||||||||||||||||||||
| 117 | join(', ', @invalid) | ||||||||||||||||||||||||||||
| 118 | ) | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||||||||||
| 122 | 70 | ); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | around database_events => sub { | ||||||||||||||||||||||||||||
| 125 | 95 | ▶ | my ($orig,$self) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 95 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 5 | ▶ | ex2err($orig, $self, ref $_[0] eq 'ARRAY' ? $_[0] : \@_) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 129 | or return; | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | return wantarray | ||||||||||||||||||||||||||||
| 133 | 94 | ▶ | ? @{ $self->$orig || [] } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 134 | : $self->$orig; | ||||||||||||||||||||||||||||
| 135 | 70 | }; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head2 fields | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Gets and set which fields to monitor for C<database_event>. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | $view->fields('id'); | ||||||||||||||||||||||||||||
| 142 | $view->fields('id', 'name'); | ||||||||||||||||||||||||||||
| 143 | $view->fields( 'id, name' ); | ||||||||||||||||||||||||||||
| 144 | $view->fields( [ 'id', 'name' ] ); | ||||||||||||||||||||||||||||
| 145 | $view->fields( qw[ id name ] ); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | my @fields = $view->fields; | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | has fields => ( | ||||||||||||||||||||||||||||
| 152 | is => 'rw', | ||||||||||||||||||||||||||||
| 153 | coerce => sub { | ||||||||||||||||||||||||||||
| 154 | 4 | ▶ | my @fields = uniq @{parse_list_arg($_[0])}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 155 | 4 | ▶ | @fields ? \@fields : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | }, | ||||||||||||||||||||||||||||
| 157 | 70 | ); | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | around fields => sub { | ||||||||||||||||||||||||||||
| 160 | 21 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||
| 161 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | 21 | my $fields = parse_list_arg( @_ ); | |||||||||||||||||||||||||||
| 163 | 21 | ▶ | $self->$orig($fields) if @$fields; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 21 | ▶ | return wantarray ? @{ $self->$orig || [] } : $self->$orig; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 166 | 70 | }; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head2 table | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Gets or set the table on which the trigger works, as a L<SQL::Translator::Schema::Table> object. | ||||||||||||||||||||||||||||
| 171 | $trigger->table($triggered_table); | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 70 | has table => ( is => 'rw', isa => schema_obj('Table'), weak_ref => 1 ); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 70 | around table => \&ex2err; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub on_table { | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =pod | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head2 on_table | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | Gets or set the table name on which the trigger works, as a string. | ||||||||||||||||||||||||||||
| 186 | $trigger->on_table('foo'); | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 81 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
on_table: called CC=3 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 81 | ▶ | if ( @_ == 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | my $table = $self->schema->get_table($arg); | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | die "Table named $arg doesn't exist" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | if !$table; | ||||||||||||||||||||||||||||
| 195 | 0 | $self->table($table); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 81 | return $self->table->name; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =head2 action | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | Gets or set the action of the trigger. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | $trigger->action( | ||||||||||||||||||||||||||||
| 205 | q[ | ||||||||||||||||||||||||||||
| 206 | BEGIN | ||||||||||||||||||||||||||||
| 207 | select ...; | ||||||||||||||||||||||||||||
| 208 | update ...; | ||||||||||||||||||||||||||||
| 209 | END | ||||||||||||||||||||||||||||
| 210 | ] | ||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 70 | has action => ( is => 'rw', default => quote_sub(q{ '' }) ); | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | sub is_valid { | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =pod | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head2 is_valid | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Determine whether the trigger is valid or not. | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | my $ok = $trigger->is_valid; | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 2 | for my $attr ( | |||||||||||||||||||||||||||
| 232 | qw[ name perform_action_when database_events on_table action ] | ||||||||||||||||||||||||||||
| 233 | ) { | ||||||||||||||||||||||||||||
| 234 | 10 | ▶ | return $self->error("Invalid: missing '$attr'") unless $self->$attr(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 2 | ▶ | return $self->error("Missing fields for UPDATE ON") if | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->database_event eq "update_on" and not $self->fields
MC/DC0%0/2
$self->database_event eq "update_on" and not $self->fields
$self->database_event eq "update_on"
not $self->fields
Truth table33%1/3
A and not(B)
A= $self->database_event eq "update_on"B= not $self->fields
| |||||||||||||||||||||||||||||
| 238 | $self->database_event eq 'update_on' && !$self->fields; | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 2 | return 1; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =head2 name | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | Get or set the trigger's name. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | my $name = $trigger->name('foo'); | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | =cut | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 70 | has name => ( is => 'rw', default => quote_sub(q{ '' }) ); | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =head2 order | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | Get or set the trigger's order. | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | my $order = $trigger->order(3); | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 70 | has order => ( is => 'rw', default => quote_sub(q{ 0 }) ); | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | around order => sub { | ||||||||||||||||||||||||||||
| 264 | 167 | ▶ | my ( $orig, $self, $arg ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 167 | ▶ | if ( defined $arg && $arg =~ /^\d+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $arg and $arg =~ /^\d+$/
MC/DC50%1/2
defined $arg and $arg =~ /^\d+$/
defined $arg
$arg =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $argB= $arg =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 267 | 72 | return $self->$orig($arg); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 95 | return $self->$orig; | |||||||||||||||||||||||||||
| 271 | 70 | }; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | =head2 scope | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | Get or set the trigger's scope (row or statement). | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | my $scope = $trigger->scope('statement'); | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 70 | has scope => ( | |||||||||||||||||||||||||||
| 282 | is => 'rw', | ||||||||||||||||||||||||||||
| 283 | isa => enum([qw(row statement)], { | ||||||||||||||||||||||||||||
| 284 | msg => "Invalid scope '%s'", icase => 1, allow_undef => 1, | ||||||||||||||||||||||||||||
| 285 | }), | ||||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 70 | around scope => \&ex2err; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =head2 schema | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | Get or set the trigger's schema object. | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | $trigger->schema( $schema ); | ||||||||||||||||||||||||||||
| 296 | my $schema = $trigger->schema; | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 70 | has schema => (is => 'rw', isa => schema_obj('Schema'), weak_ref => 1 ); | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 70 | around schema => \&ex2err; | |||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | sub compare_arrays { | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | =pod | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =head2 compare_arrays | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | Compare two arrays. | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =cut | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 3 | ▶ | my ($first, $second) = @_; | ||||||||||||||||||||||||||
|
Subroutine
compare_arrays: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||
| 315 | 70 | ▶ | no warnings; # silence spurious -w undef complaints | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 3 | ▶ | return 0 unless (ref $first eq 'ARRAY' and ref $second eq 'ARRAY' ) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $first eq "ARRAY" and ref $second eq "ARRAY"
MC/DC0%0/2
ref $first eq "ARRAY" and ref $second eq "ARRAY"
ref $first eq "ARRAY"
ref $second eq "ARRAY"
Truth table33%1/3
A and B
A= ref $first eq "ARRAY"B= ref $second eq "ARRAY"
| |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 3 | ▶ | return 0 unless @$first == @$second; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 2 | my @first = sort @$first; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 2 | my @second = sort @$second; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 2 | ▶ | for (my $i = 0; $i < scalar @first; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 3 | ▶ | return 0 if @first[$i] ne @second[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 2 | return 1; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =head2 equals | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | Determines if this trigger is the same as another | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | my $is_identical = $trigger1->equals( $trigger2 ); | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =cut | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | around equals => sub { | ||||||||||||||||||||||||||||
| 341 | 3 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=25.8
| |||||||||||||||||||||||||||||
| 342 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 343 | 3 | my $other = shift; | |||||||||||||||||||||||||||
| 344 | 3 | my $case_insensitive = shift; | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 3 | ▶ | return 0 unless $self->$orig($other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 3 | my %names; | |||||||||||||||||||||||||||
| 349 | 3 | for my $name ( $self->name, $other->name ) { | |||||||||||||||||||||||||||
| 350 | 6 | ▶ | $name = lc $name if $case_insensitive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 6 | $names{ $name }++; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 3 | ▶ | if ( keys %names > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 0 | return $self->error('Names not equal'); | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 3 | ▶ | if ( !$self->perform_action_when eq $other->perform_action_when ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | 0 | return $self->error('perform_action_when differs'); | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 3 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | !compare_arrays( [$self->database_events], [$other->database_events] ) | ||||||||||||||||||||||||||||
| 364 | ) { | ||||||||||||||||||||||||||||
| 365 | 1 | return $self->error('database_events differ'); | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 2 | ▶ | if ( $self->on_table ne $other->on_table ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | return $self->error('on_table differs'); | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 2 | ▶ | if ( $self->action ne $other->action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | return $self->error('action differs'); | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 2 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | !$self->_compare_objects( scalar $self->extra, scalar $other->extra ) | ||||||||||||||||||||||||||||
| 378 | ) { | ||||||||||||||||||||||||||||
| 379 | 0 | return $self->error('extras differ'); | |||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 2 | return 1; | |||||||||||||||||||||||||||
| 383 | 70 | }; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | # Must come after all 'has' declarations | ||||||||||||||||||||||||||||
| 386 | 70 | around new => \&ex2err; | |||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 70 | 1; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =pod | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | Anonymous, | ||||||||||||||||||||||||||||
| 395 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | =cut | ||||||||||||||||||||||||||||