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
|
Rev | Line | |
---|
[2] | 1 | package Bookmark; |
---|
| 2 | |
---|
[25] | 3 | use Moose; |
---|
[66] | 4 | use HTTP::Date qw{time2isoz}; |
---|
[2] | 5 | |
---|
[44] | 6 | has id => ( is => 'ro' ); |
---|
[25] | 7 | has uri => ( is => 'rw' ); |
---|
| 8 | has title => ( is => 'rw' ); |
---|
[44] | 9 | has ctime => ( is => 'ro' ); |
---|
| 10 | has mtime => ( |
---|
| 11 | is => 'ro', |
---|
| 12 | # mtime defaults to ctime |
---|
| 13 | default => sub { $_[0]->ctime }, |
---|
| 14 | lazy => 1, |
---|
| 15 | ); |
---|
[25] | 16 | has tags => ( is => 'rw' ); |
---|
| 17 | has bookmark_uri => ( is => 'rw' ); |
---|
[66] | 18 | has exists => ( is => 'ro' ); |
---|
[2] | 19 | |
---|
[66] | 20 | sub created { scalar localtime $_[0]->ctime } |
---|
| 21 | sub updated { scalar localtime $_[0]->mtime } |
---|
| 22 | sub created_iso { (my $iso = time2isoz($_[0]->ctime)) =~ s/\D//g; return $iso; } |
---|
| 23 | sub updated_iso { (my $iso = time2isoz($_[0]->ctime)) =~ s/\D//g; return $iso; } |
---|
| 24 | |
---|
[25] | 25 | sub 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 | |
---|
| 33 | sub 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 |
---|
| 47 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.