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

NAME

App::Dochazka::REST::Model::Component - component class

SYNOPSIS

    use App::Dochazka::REST::Model::Component;

    ...

DATA MODEL

Components in the database

   CREATE TABLE components (
       cid         serial PRIMARY KEY,
       path        varchar(2048) UNIQUE NOT NULL,
       source      text NOT NULL,
       acl         varchar(16) NOT NULL,
       validations textj
   )

Components in the Perl API

  • constructor (spawn)

  • basic accessors (cid, path, source, acl, validations)

  • reset (recycles an existing object by setting it to desired state)

  • TO_JSON (returns 'unblessed' version of an Activity object)

  • compare (compare two objects)

  • clone (clone an object)

  • insert (inserts object into database)

  • update (updates database to match the object)

  • delete (deletes record from database if nothing references it)

  • load_by_cid (loads a single activity into an object)

  • load_by_path (loads a single activity into an object)

App::Dochazka::REST::Model::Component also exports some convenience functions:

For basic component object workflow, see the unit tests in t/model/component.t.

METHODS

insert

Instance method. Takes the object, as it is, and attempts to insert it into the database. On success, overwrites object attributes with field values actually inserted. Returns a status object.

update

Instance method. Assuming that the object has been prepared, i.e. the CID corresponds to the component to be updated and the attributes have been changed as desired, this function runs the actual UPDATE, hopefully bringing the database into line with the object. Overwrites all the object's attributes with the values actually written to the database. Returns status object.

delete

Instance method. Assuming the CID really corresponds to the component to be deleted, this method will execute the DELETE statement in the database. No attempt is made to protect from possible deleterious consequences of deleting components. Returns a status object.

load_by_cid

Loads component from database, by the CID provided in the argument list, into a newly-spawned object. The CID must be an exact match. Returns a status object: if the object is loaded, the status code will be 'DISPATCH_RECORDS_FOUND' and the object will be in the payload; if the CID is not found in the database, the status code will be 'DISPATCH_NO_RECORDS_FOUND'. A non-OK status indicates a DBI error.

load_by_path

Analogous method to "load_by_cid".

create_file

Create Mason component file under $comp_root

delete_file

Delete Mason component file under $comp_root

generate

Generate output

FUNCTIONS

The following functions are not object methods.

cid_exists

Boolean function

path_exists

Boolean function

cid_by_path

Given a path, attempt to retrieve the corresponding CID. Returns CID or undef on failure.

get_all_components

Returns a reference to a hash of hashes, where each hash is one component object.

AUTHOR

Nathan Cutler, <presnypreklad@gmail.com>