An Introduction to Class::DBI - Bonus Material 47

Class::DBI Gotchas

Two Objects in Memory, One Object in the DB

  • The same database row can be in memory as two objects

        package main;
    
        my ($tom_hanks)   = FilmBuff::Person->search(name => 'Tom Hanks');
        my ($kevin_bacon) = FilmBuff::Person->search(name => 'Kevin Bacon');
    
        my ($toms_apollo_13)   = grep { $_->title eq 'Apollo 13' } map { $_->film } $tom_hanks->credits;
        my ($kevins_apollo_13) = grep { $_->title eq 'Apollo 13' } map { $_->film } $kevin_bacon->credits;
    
        $kevins_apollo_13->title('Apollo XIII');
    
        print "Tom Acted in the film:   ", $toms_apollo_13->title, "\n";
        print "Kevin Acted in the film: ", $kevins_apollo_13->title, "\n";
    
  • This prints out:

        Tom Acted in the film:    Apollo 13
        Kevin Acted in the film:  Apollo XIII
    

 

YAPC::Canada << Previous | Index | Next >>
Copyright © 2003 Michael Graham