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

AxKit::App::TABOO::Data::Comment - Comment Data object for TABOO

SYNOPSIS

  use AxKit::App::TABOO::Data::Comment;
  $comment = AxKit::App::TABOO::Data::Comment->new();
  $comment->load('*', $commentpath, $sectionid, $commentname);
  $comment->tree('*');
  $comment->adduserinfo();
  $timestamp = $comment->timestamp();

DESCRIPTION

This Data class contains a comment, which may be posted by any registered user of the site. Each object will also contain an identifier of replies to the comment, that may be replaced with a reference to another comment object.

METHODS

This class implements several methods, reimplements the load method, but inherits some from AxKit::App::TABOO::Data.

new()

The constructor. Nothing special.

load($what, $commentpath, $section, $storyname)

The load method is reimplemented to support a more elaborate scheme for identifying comments, as well as the ability of selecting a subset of data to load. It now takes four arguments, three of them are identical to those of AxKit::App::TABOO::Data::Story.

  • The first is a comma-separated list of fields from the data storage, see "STORED DATA" for details and available values. For all fields, use '*'.

  • The second is a commentpath. Conceptually, a commentpath is a string that identifies a comment by appending the username of the poster for each reply posted, separated by a /. Thus, commentpaths will grow as people respond to each other's comments. For example, if user bar replies to user foo, the commentpath to bar's comment will be /foo/bar. The commenpath will typically be in the URI of a comment.

  • The third parameter is a word identifying a section which the story has been posted to. Typically, this string will be taken directly from the URI.

  • The fourth parameter is a unique identifier for the story. This too will typically be derived from the URI directly.

The $commentpath, $section amd $storyname together identifies a comment.

When loaded, the comment object will also contain an array of commentpaths of the replies to the comment. There is currently no method to retrieve this array, but you shouldn't need to.

tree($what)

Once you've load()ed the object, you may call this method on it. It will replace the commentpath array with references to the objects, and does it recursively, so you'll have references with references (etc) to all comments that are below this comment. Furthermore, it calls adduserinfo() (below) on all the objects, so after having called tree() on an object, you should have everything that's intersting in there.

Like load(), tree($what) takes an argument, a comma-separated list of fields from the data storage, see "STORED DATA" available values. For all fields, use '*'.

root($section, $storyname)

The / commentpath does not refer to a comment. The root is simply not a comment, so you can't load( ... , '/', ... , ...). To address this problem, the root method returns a reference to an array containing all the commentpaths of comments attached directly to a story. You may then run through the array and call load on each element in the array. It takes two arguments, an identifier for the section and for the story, see load(). This is slightly inelegant, since it does not deal with a single object of this class like the others do, but it was the best solution I found now.

adduserinfo()

When data has been loaded into an object of this class, it will contain a string only identifying the user who posted the comment. This method will replace that string with a reference to a AxKit::App::TABOO::Data::User-object, and that object's load_name method will be called. After this has been done, the story will effectively have all the user information it needs.

timestamp([($section, $storyname)])

The timestamp method will retrieve the timestamp of the comment. If the timestamp has been loaded earlier from the data storage (for example by the load method), you need not supply any arguments. If the timestamp is not available, you must supply the section and storyname identifiers, the method will then load it into the data structure first.

The timestamp method will return a Time::Piece object with the requested time information.

STORED DATA

The data is stored in named fields, and for certain uses, it is good to know them. If you want to subclass this class, you might want to use the same names, see the documentation of AxKit::APP::TABOO::Data for more about this.

In this class it gets even more interesting, because you may pass a list of those to the load method. This is useful if you for example just want the title of the comments, not all their content.

These are the names of the stored data of this class:

  • commentpath - the identifying commentpath, as described above.

  • storyname - an identifier for the story, a simple word you use to retrieve the desired object.

  • sectionid - an identifier for the section, also a simple word you use to retrieve the desired object.

  • title - the title for the comment chosen by the poster.

  • content - the full comment text.

  • timestamp - typically the time when the comment was posted. See also the timestamp() method.

  • username - the username of the user who posted the comment.

XML representation

The write_xml() method, implemented in the parent class, can be used to create an XML representation of the data in the object. The above names will be used as element names. The xmlelement() and xmlns() methods can be used to set the name of the root element and the namespace respectively. Usually, it doesn't make sense to change the defaults, which are

  • reply

  • http://www.kjetil.kjernsmo.net/software/TABOO/NS/Comment/Output

BUGS/TODO

With the introduction of Plurals, the tree, root and generally the load code needs to be reworked a bit. It may still work as it used to, be expect some larger changes in both the code and API in shortly forthcoming releases. For that reason, comments really don't work in this release.

FORMALITIES

See AxKit::App::TABOO.