An Introduction to Class::DBI - Bonus Material 45

Class::DBI Gotchas

Automatic updating with autoupdate()

  • If you don't want to update when you are finished with your changes, you can tell Class::DBI to autoupdate()

  • This causes a database 'UPDATE' to be issued after every change to an attribute.

  • This can cost performance, but it can make things much easier.

  • You can set autoupdate() for all objects, for objects of a single class, or for a single object

    • All classes derived from Class::DBI:

          use Class::DBI;
          Class::DBI->autoupdate(1);
      
    • OR: All classes derived from your base class

          package FilmBuff::DBI;
          use base 'Class::DBI';
          FilmBuff::DBI->set_db('Main', 'dbi:mysql:test', 'test', '');
          FilmBuff::DBI->autoupdate(1);
      
          package FilmBuff::Film;
          use base 'FilmBuff::DBI';
      
    • OR: Any particular class

          package FilmBuff::DBI;
          use base 'Class::DBI';
      
          package FilmBuff::Film;
          use base 'FilmBuff::DBI';
          FilmBuff::Film->autoupdate(1);
      
    • OR: Any given object

          package FilmBuff::DBI;
          use base 'Class::DBI';
      
          package FilmBuff::Film;
          use base 'FilmBuff::DBI';
      
          my $film = FilmBuff::Film->create({
              title => 'A Fistful of Dollars',
          });
      
          $film->autoupdate(1);
      

 

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