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

NAME

SimpleDB::Class::Item - An object representation from an item in a SimpleDB domain.

VERSION

version 1.0503

DESCRIPTION

An object representation from an item in a SimpleDB domain.

METHODS

The following methods are available from this class.

set_domain_name ( name )

Class method. Used to set the SimpleDB domain name associated with a sublcass.

name

The domain name to set.

domain_name ( )

Class method. After set_domain_name() has been called, there will be a domain_name method, that will return the value of the domain name.

add_attributes ( list )

Class method. Adds more attributes to this class. NOTE: This will add a method to your class which can be used as an accessor/mutator. Therefore make sure to avoid method name conflicts with this class.

list

A hashref that holds a list of attributes and their properties (a hashref itself). Example: title => { isa => 'Str', default => 'Untitled' }

attribute

The attribute name is key in the hashref.

isa

The type of data represented by this attribute. See SimpleDB::Class::Types for the available types.

default

The default value for this attribute. This should be specified even if it is 'None' or 'Undefined' or 'Null', because actuall null queries are slow in SimpleDB.

trigger

A sub reference that will be called like a method (has reference to $self), and is also passed the new and old values of this attribute. Behind the scenes is a Moose trigger. See also "Triggers" in Moose::Manual::Attributes.

has_many ( method, class, attribute )

Class method. Sets up a 1:N relationship between this class and a child class.

WARNING: With this method you need to be aware that SimpleDB is eventually consistent. See "Eventual Consistency" in SimpleDB::Class for details.

method

The name of the method in this class you wish to use to access the relationship with the child class.

class

The class name of the class you're creating the child relationship with.

attribute

The attribute in the child class that represents this class' id.

options

A hash containing options that will modify the method created.

mate

The name of the attribute that will be created in class to refer back to this object. If specified, a reference to this object will be set in class when it is instantiated to avoid stale references.

consistent

A boolean which can enable SimpleDB's ConsistentRead option. Defaults to 0.

has_many_generated_method ( [ options ] )

This is the documentation for the method generated by has_many. It returns a SimpleDB::Class::ResultSet object with a list of the related children to this class.

options

A hash of options to modify the result set at run time.

where

A where clause as defined by SimpleDB::Class::SQL. This new clause will automatically be added to the relationship clause, so whatever you specify here is only to further limit the results returned.

order_by

An order_by clause as defined by SimpleDB::Class::SQL. By default no order is specified.

limit

A limit clause as defined by SimpleDB::Class::SQL. By default all items in the relationship will be returned.

consistent

A boolean that can enable SimpleDB's ConsistentRead option. Setting this will override whatever was set in has_many, if anything.

set

A hash reference of attribute names and values that will be applied to each object returned from the result set. The mate option in has_many can already set one of these.

belongs_to ( method, class, attribute )

Class method. Adds a 1:N relationship between another class and this one.

method

The method name to create to represent this relationship in this class.

class

The class name of the parent class you're relating this class to.

attribute

The attribute in this class' attribute list that represents the id of the parent class.

options

A hash of options to modify the created method.

mate

The name of the attribute that will be created in class to refer back to this object. If specified, a reference to this object will be set in class when it is instantiated to avoid stale references. This would only be useful in the case of a 1:1 relationship.

consistent

A boolean indicating whether to enable the SimpleDB's ConsistentRead option.

belongs_to_generated_method ( [ item ] )

This is the documentation for the method that belongs_to generates. This method caches the item it retrieves for faster future retrievals.

NOTE: Will return undef if the attribute specified has no value at the time it is called.

item

You can optionally precache the item that this method would produce, if you already have it by passing it to the method here. If you choose to use this option, make sure what you're setting here actually matches the id attribute that would normally be used to find the item in question.

has_belongs_to_generated_method

Returns a boolean indicating whether the generated method is storing a cached result.

clear_belongs_to_generated_method

Clears the cached result stored by the generated method. This method will be automatically called if a new value is set for the attribute.

attributes ( )

Class method. Returns the hashref of attributes set by the add_attributes() method.

recast_using ( attribute_name )

Class method. Sets an attribue name to use to recast this object as another class. This allows you to pull multiple object types from the same domain. If the attribute is defined when reading the information from SimpleDB, the object will be cast as the classname returned, rather than the classname associated with the domain. The new class must be a subclass of the class associated with the domain, because you cannot set_domain_name for the same domain twice, or you will break SimpleDB::Class.

attribute_name

The name of an attribute defined by add_attributes.

update ( attributes )

Update a bunch of attributes all at once. Returns a reference to $self so it can be chained into other methods.

attributes

A hash reference containing attribute names and values.

new ( params )

Constructor.

params

A hash.

id

The unique identifier (ItemName) of the item represented by this class. If you don't pass this in, an item ID will be generated for you automatically.

simpledb

Required. A SimpleDB::Class object.

simpledb ( )

Returns the simpledb passed into the constructor.

id ( )

Returns the unique id of this item. Note: The primary key ItemName (or id as we call it) is a special property of an item that doesn't exist in it's own data. So if you want to search on the id, you have to use itemName() in your queries as the attribute name.

copy ( [ id ] )

Creates a duplicate of this object, inserts it into the database, and returns a reference to it.

id

If you want to assign a specific id to the copy, then you can do it with this parameter.

delete

Removes this item from the database.

delete_attribute

Removes a specific attribute from this item in the database. Great in conjunction with add_attribute().

generate_uuid ( )

Class method. Generates a unique UUID that can be used as a unique id for new items.

put ( )

Inserts/updates the current attributes of this Item object to the database. Returns a reference to $self so it can be chained into other methods.

to_hashref ( )

Returns a hash reference of the attributes asscoiated with this item.

parse_value ( name, value )

Class method. Returns the proper type for an attribute value in this class. So it could take a date string and turn it into a DateTime object. See stringify_value for the opposite.

name

The name of the attribute to parse.

value

The current stringified value to parse.

stringify_value ( name, value )

Class method. Formats an attribute as a string using one of the SimpleDB::Class::Types to_* functions in this class. See parse_value, as this is the reverse of that.

name

The name of the attribute to format.

value

The value to format.

stringify_values ( name, values )

Class method. Same as stringify_value, but takes into account array types in addition to scalars.

name

The name of the attribute to format.

values

The value to format.

LEGAL

SimpleDB::Class is Copyright 2009-2010 Plain Black Corporation (http://www.plainblack.com/) and is licensed under the same terms as Perl itself.