Andrew Sterling Hanenkamp > DustyDB-0.06 > DustyDB::Record

Download:
DustyDB-0.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.06   Source  

NAME ^

DustyDB::Record - role for DustyDB models

VERSION ^

version 0.06

SYNOPSIS ^

  package MyModel;
  use DustyDB::Object;

  has key name => (
      is  => 'rw',
      isa => 'Str',
  );
  has description => (
      is => 'rw',
      isa => 'Str',
  );

DESCRIPTION ^

Do not use this class directly. Use DustyDB::Object instead. The attributes and methods shown here are available in any class that uses DustyDB::Object because such classes do this role.

ATTRIBUTES ^

db

This is a required attribute that must be set to a DustyDB object that will be used to save this. In general, you will never need to set this yourself.

However, if you want to construct your record class directly, you can do something like this.

  my $db = DustyDB->new( path => 'foo.db' );
  my $object = MyModel->new( db => $db, name => 'foo', description => 'bar' );

METHODS ^

save

  my $key = $self->save;

This method saves the object into the database and returns a key identifying the object. The key is a hash reference created using the attributes that have the DustyDB::Key trait set.

delete

  $self->delete;

This method delets the object from the database. This does not invalidate the object in memory or alter it in any other way.

CAVEATS ^

When creating your models you cannot have an attribute named db or an attribute named class_name. The db name is used directly as an attribute by this role and class_name may be used when storing the data in some cases.

syntax highlighting: