1package Class::DBI::Cascade::None; 2 3=head1 NAME 4 5Class::DBI::Cascade::None - Do nothing upon deletion 6 7=head1 DESCRIPTION 8 9This is a Cascading Delete strategy that will do nothing, leaving 10orphaned records behind. 11 12It is the base class for most ofther Cascade strategies, and so provides 13several important methods: 14 15=head1 CONSTRUCTOR 16 17=head2 new 18 19 my $strategy = Cascade::Class->new($Relationship); 20 21This 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 29This will return all the objects which are foreign to $obj across the 30relationship. It's a normal Class::DBI search you can get the results 31either as a list or as an iterator. 32 33=head2 cascade 34 35 $strategy->cascade($obj); 36 37Cascade across the related objects to $obj. 38 39=head1 WRITING NEW STRATEGIES 40 41Creating a Cascade strategy should be fairly simple. You usually just 42need to inherit from here, and then supply a cascade() method that does 43the required thing with the results from foreign_for(). 44 45So, 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 58use strict; 59use warnings; 60 61sub new { 62 my ($class, $rel) = @_; 63 bless { _rel => $rel } => $class; 64} 65 66sub foreign_for { 67 my ($self, $obj) = @_; 68 return $self->{_rel} 69 ->foreign_class->search($self->{_rel}->args->{foreign_key} => $obj->id); 70} 71 72sub cascade { return; } 73 741; 75