| 1 | package Class::DBI::Cascade::None; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Class::DBI::Cascade::None - Do nothing upon deletion | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | This is a Cascading Delete strategy that will do nothing, leaving | ||
| 10 | orphaned records behind. | ||
| 11 | |||
| 12 | It is the base class for most ofther Cascade strategies, and so provides | ||
| 13 | several important methods: | ||
| 14 | |||
| 15 | =head1 CONSTRUCTOR | ||
| 16 | |||
| 17 | =head2 new | ||
| 18 | |||
| 19 | my $strategy = Cascade::Class->new($Relationship); | ||
| 20 | |||
| 21 | This must be instantiated with a Class::DBI::Relationship object. | ||
| 22 | |||
| 23 | =head1 METHODS | ||
| 24 | |||
| 25 | =head2 foreign_for | ||
| 26 | |||
| 27 | my $iterator = $strategy->foreign_for($obj); | ||
| 28 | |||
| 29 | This will return all the objects which are foreign to $obj across the | ||
| 30 | relationship. It's a normal Class::DBI search you can get the results | ||
| 31 | either as a list or as an iterator. | ||
| 32 | |||
| 33 | =head2 cascade | ||
| 34 | |||
| 35 | $strategy->cascade($obj); | ||
| 36 | |||
| 37 | Cascade across the related objects to $obj. | ||
| 38 | |||
| 39 | =head1 WRITING NEW STRATEGIES | ||
| 40 | |||
| 41 | Creating a Cascade strategy should be fairly simple. You usually just | ||
| 42 | need to inherit from here, and then supply a cascade() method that does | ||
| 43 | the required thing with the results from foreign_for(). | ||
| 44 | |||
| 45 | So, for example, Cascade::Delete is implemented simply as: | ||
| 46 | |||
| 47 | package Class::DBI::Cascade::Delete; | ||
| 48 | |||
| 49 | use base 'Class::DBI::Cascade::None'; | ||
| 50 | |||
| 51 | sub cascade { | ||
| 52 | my ($self, $obj) = @_; | ||
| 53 | $self->foreign_for($obj)->delete_all; | ||
| 54 | } | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 59 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 60 | |||
| 61 | 2 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 62 | 2 | my ($class, $rel) = @_; | |
| 63 | 2 | bless { _rel => $rel } => $class; | |
| 64 | } | ||
| 65 | |||
| 66 | 0 | ▶ | sub foreign_for { |
|
Subroutine
foreign_for: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 67 | 0 | my ($self, $obj) = @_; | |
| 68 | return $self->{_rel} | ||
| 69 | 0 | ->foreign_class->search($self->{_rel}->args->{foreign_key} => $obj->id); | |
| 70 | } | ||
| 71 | |||
| 72 | 0 | ▶ | sub cascade { return; } |
|
Subroutine
cascade: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 73 | |||
| 74 | 2 | 1; | |