source: bookmarks/trunk/lib/Bookmark.pm @ 73

Last change on this file since 73 was 70, checked in by peter, 11 years ago
  • moved the *.pm files into the lib directory
  • changed BookmarksList to Bookmarks::List
  • changed BookmarkController to Bookmarks::Controller
  • the start script sets PERL5LIB before running starman
File size: 1.1 KB
RevLine 
[2]1package Bookmark;
2
[25]3use Moose;
[66]4use HTTP::Date qw{time2isoz};
[2]5
[44]6has id    => ( is => 'ro' );
[25]7has uri   => ( is => 'rw' );
8has title => ( is => 'rw' );
[44]9has ctime => ( is => 'ro' );
10has mtime => (
11    is => 'ro',
12    # mtime defaults to ctime
13    default => sub { $_[0]->ctime },
14    lazy => 1,
15);
[25]16has tags  => ( is => 'rw' );
17has bookmark_uri => ( is => 'rw' );
[66]18has exists => ( is => 'ro' );
[2]19
[66]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
[25]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
[2]46# module return
471;
Note: See TracBrowser for help on using the repository browser.