source: bookmarks/trunk/Bookmark.pm @ 69

Last change on this file since 69 was 66, checked in by peter, 10 years ago
  • the bookmark.tt template takes a hash or object named bookmark as its only variable
  • moved the calculation of a human-readable timestamp and the ISO timestamps for the WayBack machine from the BookmarkController class into the Bookmark class as methods (created, updated, created_iso, and updated_iso
  • moved the exists flag into the Bookmark class as an attribute
File size: 1.1 KB
Line 
1package Bookmark;
2
3use Moose;
4use HTTP::Date qw{time2isoz};
5
6has id    => ( is => 'ro' );
7has uri   => ( is => 'rw' );
8has title => ( is => 'rw' );
9has ctime => ( is => 'ro' );
10has mtime => (
11    is => 'ro',
12    # mtime defaults to ctime
13    default => sub { $_[0]->ctime },
14    lazy => 1,
15);
16has tags  => ( is => 'rw' );
17has bookmark_uri => ( is => 'rw' );
18has exists => ( is => 'ro' );
19
20sub created { scalar localtime $_[0]->ctime }
21sub updated { scalar localtime $_[0]->mtime }
22sub created_iso { (my $iso = time2isoz($_[0]->ctime)) =~ s/\D//g; return $iso; }
23sub updated_iso { (my $iso = time2isoz($_[0]->ctime)) =~ s/\D//g; return $iso; }
24
25sub BUILD {
26    my $self = shift;
27    my $args = shift;
28    if ($args->{base_uri}) {
29        $self->bookmark_uri(URI->new_abs($self->id, $args->{base_uri}));
30    }
31}
32
33sub TO_JSON {
34    my $self = shift;
35    return {
36        id    => $self->id,
37        uri   => $self->uri,
38        title => $self->title,
39        ctime => $self->ctime,
40        mtime => $self->mtime,
41        tags  => $self->tags,
42        ($self->bookmark_uri ? (bookmark_uri => $self->bookmark_uri->canonical->as_string) : ()),
43    };
44}
45
46# module return
471;
Note: See TracBrowser for help on using the repository browser.