Changeset 25 in bookmarks for trunk/Bookmark.pm


Ignore:
Timestamp:
05/23/13 00:37:57 (11 years ago)
Author:
peter
Message:
  • 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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bookmark.pm

    r2 r25  
    11package Bookmark; 
    22 
    3 use Class::Accessor qw{antlers}; 
     3use Moose; 
    44 
    5 has id    => ( is => 'ro' ); 
    6 has uri   => ( is => 'ro' ); 
    7 has ctime => ( is => 'ro' ); 
    8 has mtime => ( is => 'ro' ); 
     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} 
    933 
    1034# module return 
Note: See TracChangeset for help on using the changeset viewer.