source: bookmarks/trunk/Bookmark.pm @ 41

Last change on this file since 41 was 25, checked in by peter, 11 years ago
  • Bookmark uses Moose
    • the Bookmarks base_uri should be passed to the constructor to set the bookmark_uri attribute of the Bookmark
    • added a TO_JSON method to serialize the URIs to strings for JSON
  • use JSON::convert_blessed to trigger calling Bookmark::TO_JSON
  • added a private _sth_tags_from_uri attribute to Bookmarks
  • Bookmarks::get_tags can be called with a uri parameter to fetch a list of tags for that resource
  • Bookmarks::get_bookmark() returns a Bookmark object
  • Bookmarks::get_resources() returns an array of Bookmark objects
File size: 765 bytes
Line 
1package Bookmark;
2
3use Moose;
4
5has id    => ( is => 'rw' );
6has uri   => ( is => 'rw' );
7has title => ( is => 'rw' );
8has ctime => ( is => 'rw' );
9has mtime => ( is => 'rw' );
10has tags  => ( is => 'rw' );
11has bookmark_uri => ( is => 'rw' );
12
13sub BUILD {
14    my $self = shift;
15    my $args = shift;
16    if ($args->{base_uri}) {
17        $self->bookmark_uri(URI->new_abs($self->id, $args->{base_uri}));
18    }
19}
20
21sub TO_JSON {
22    my $self = shift;
23    return {
24        id    => $self->id,
25        uri   => $self->uri,
26        title => $self->title,
27        ctime => $self->ctime,
28        mtime => $self->mtime,
29        tags  => $self->tags,
30        ($self->bookmark_uri ? (bookmark_uri => $self->bookmark_uri->canonical->as_string) : ()),
31    };
32}
33
34# module return
351;
Note: See TracBrowser for help on using the repository browser.