The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

version 0.0500

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 ( )

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. Defaults to 'Str' if left out. Options are 'Str', 'Int', 'HashRef', and 'DateTime'.

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. Works just like 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.

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.

attributes ( )

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

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.

attributes

Required. A hashref containing the names and values of the attributes associated with this item.

{attribute} ( [ value ] )

For each attribute passed into the constructor, an accessor / mutator will be added to this class allowing you to get or set it's current value.

If specified, sets the current value of the attribute. Note, that this doesn't update the database, for that you must call the put() method.

simpledb ( )

Returns the simpledb passed into the constructor.

id ( )

Returns the unique id of this item. Note: Even though the primary key ItemName (or id as we call it) is a special property of an item, an id attribute is also automatically added to every item when put is called, which contains the same value as the ItemName. This is so you can perform searches based upon the id, which is not something you can normally do with a Select in SimpleDB.

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.

LEGAL

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