Last change
on this file since 33 was
25,
checked in by peter, 12 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 | |
---|
1 | package Bookmark; |
---|
2 | |
---|
3 | use Moose; |
---|
4 | |
---|
5 | has id => ( is => 'rw' ); |
---|
6 | has uri => ( is => 'rw' ); |
---|
7 | has title => ( is => 'rw' ); |
---|
8 | has ctime => ( is => 'rw' ); |
---|
9 | has mtime => ( is => 'rw' ); |
---|
10 | has tags => ( is => 'rw' ); |
---|
11 | has bookmark_uri => ( is => 'rw' ); |
---|
12 | |
---|
13 | sub 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 | |
---|
21 | sub 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 |
---|
35 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.