The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  Kwiki::DB::ClassDBI - A Class::DBI wrapper for Kwiki

SYNOPSIS

  package Kwiki::MyPlugin;
  use Kwiki::Plugin -Base;

  # setup Music::Artist and Music::CD as in Class::DBI pod.
  sub init {
      super;
      $self->hub->config->add_field("db_class" => 'Kwiki::DB::DBI');
      field db => -init => "\$self->hub->load_class('db')";

      $self->db->entity( artist => 'Music::Artist' );
      $self->db->entity(     cd => 'Music::CD'     );
      $self->connection("dbi:SQLite:dbfile.sqlt");
  }

  sub my_action {
      $self->cdb->artist->create(...)
  }

DESCRIPTION

This module privdes a bridge between Class::DBI and Kwiki programming environment. After adding Kwiki::DB::ClassDBI into your plugins file, there will be a convienent $self->hub->cdbi reference to an instantiated object which acts as the door to all your Class::DBI based classes.

Instead of using class name to access data, this module requires you give several "entity" names in the init phrase. Each entity has a short name, and a corresponding Class::DBI based class name. Writing

    $self->hub->cdbi->entity( artist => 'Music::Artist' );

would create a object held in $self->db->artist, and delegates all methods to Music::Artist. So these two lines are doing the same work:

    $self->hub->cdbi->artist->create({ artistid => 1, name => 'U2' });
    Music::Artist->create({ artistid => 1, name => 'U2' });

They return the same type of value, because $self->db->artist only delegates the create method to Music::Artist.

People could even directly use the $hub->db to access database in their kwiki template like this:

    The band is [% hub.db.artist.retrieve(1).name %].

Also, you may want to read the test t/02.classdbi-sqlite.t and t/lib/Kwiki/DB/Music* as a live example for how to use this bridge.

SEE ALSO

Class::DBI, Kwiki::DB::DBI

COPYRIGHT

Copyright 2005 by Kang-min Liu <gugod@gugod.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>