source: bookmarks/trunk/Bookmark.pm @ 44

Last change on this file since 44 was 44, checked in by peter, 11 years ago
  • make the id, ctime, and mtime attributes of Bookmark read-only
  • mtime defaults to the ctime
File size: 852 bytes
Line 
1package Bookmark;
2
3use Moose;
4
5has id    => ( is => 'ro' );
6has uri   => ( is => 'rw' );
7has title => ( is => 'rw' );
8has ctime => ( is => 'ro' );
9has mtime => (
10    is => 'ro',
11    # mtime defaults to ctime
12    default => sub { $_[0]->ctime },
13    lazy => 1,
14);
15has tags  => ( is => 'rw' );
16has bookmark_uri => ( is => 'rw' );
17
18sub BUILD {
19    my $self = shift;
20    my $args = shift;
21    if ($args->{base_uri}) {
22        $self->bookmark_uri(URI->new_abs($self->id, $args->{base_uri}));
23    }
24}
25
26sub TO_JSON {
27    my $self = shift;
28    return {
29        id    => $self->id,
30        uri   => $self->uri,
31        title => $self->title,
32        ctime => $self->ctime,
33        mtime => $self->mtime,
34        tags  => $self->tags,
35        ($self->bookmark_uri ? (bookmark_uri => $self->bookmark_uri->canonical->as_string) : ()),
36    };
37}
38
39# module return
401;
Note: See TracBrowser for help on using the repository browser.