Hakan Ardo > DBIx-HTMLView-LATEST > DBIx::HTMLView::Post

Download:
DBIx-HTMLView-LATEST.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

  DBIx::HTMLView::Post - A post in a DBI database

SYNOPSIS ^

  $post=$post_set->first;
  print $post->view_html;   # View a post

  $post->set('testf', 7);   # Set the testf field to 7
  $post->update;            # Update the database with the modified post

  $post=DBIx::HTMLView::Post->new($tab)   # Create a new post
  $post->set('testf', 7);   # Set the testf field to 7
  $post->update;            # Insert the new post in the databse

DESCRIPTION ^

This object represents a single post in a specific table in the database. It has methods to view post as well as to modify it's data and to reflect those modifications in the database.

$post=DBIx::HTMLView::Post->new($tab, $data, $sth)

Creates a new post belonging to the table $tab (a DBIx::HTMLview::Table object). $data and $sth is used to initialize the post with it's fields, which can be done in several ways:

1. To create a new empty post with no data set, simply don't specify those arguments. 2. If $data is an array reference, $sth is supposed to be the object returned by a DBI execude call with a select command, and $data should be the array ref with the data you want to create a post object of. If the same fieldname apperas twice in the select the first one is presumed to be the one belonging to this post. 3. If $data is a hash reference, it is supposed to contain Fld/Value pairs. 4. If $data is a CGI object the CGI params is supposed to be Fld/Value pairs. Note that relations in this case is defined by setting the name of the relation to the id's of the posts related to, eg it will be defined once for every post.

$post->set($fld, $val)

Set's the Fld named $fld to $val. If $val is not a DBIx::HTMLView::Fld object $post->tab->new_fld($fld,$val) is called to create the Fld object to represent this fld and it's data.

For fields data ($val) is specified as a string or as the first item of a array referenced to by $val. Relations are represented as a reference to an array of the id's of the posts being related to.

$post->got_fld($fld_name)

Returns true if we have data specified for the fld named $fld_name.

$post->pairs

 Return an array of 2*N element where eache element is the name of the field
 and his value.
 Can be used to easily make perl controls on the
 integrity of the data.

$post->view_text

Returns a string that could be used to view this post in text format

$post->view_html

Returns a string that could be used to view this post in html format.

$post->view_fmt($fmt_name, $fmt)

Returns a string represeting this post in the format named by $fmt_name as returned by DBIx::HTMLView::post_fmt($fmt_name). If $fmt is specified it will be used as the fmt strings instead of looking up a default one.

All <Var ...> will be replaced with there corisponding values or removed if they are not know, currently no such values are know here (eg all is remeved).

To include the value of an Fld in output simply put $<fld_name> in the desired place in the $fmt string. (eg $name will be replaced with the outpit of $self->fld('name')->view_fmt($fmt_name)).

If $fmt is not specified the default post fmt will be used as returned by post_fmt in DBIx::HTMLView::Table.

$fmt_name is passed on to fld objects, so it can be used to specify how the flds should be represented even if you use a custom fmt passed to $fmt.

$post->fld_names

Returns an array of the fld names currently specified in this post, use $post->tab->fld_names to list all Fld of the post.

$post->fld($fld_name) =head2 $post->val($fld_name)

Returns the Fld representing that data of the Fld named $fld_name.

$post->tab

Returns the table this post belongs to (a DBIx::HTMLView::Table object).

$post->got_id

Returns true if the id of this post is defined, which is the same as that the post is represented in the database as well (which is not true for new posts that not yet have been added to the datbase, using $post->update).

$post->id

Returns the id of this post or dies with "No id defined" if it is not defined. Se $post->got_id.

$post->update

Updates the database with the data found in this object or creats a new post in the database with that data if the id is not defined. Se $post->got_id.

syntax highlighting: