Changeset 7 in bookmarks
- Timestamp:
- 03/23/12 23:50:49 (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BookmarkApp.pm
r6 r7 11 11 use Bookmarks; 12 12 13 use URI; 14 my $base_uri = URI->new; 15 $base_uri->scheme('http'); 16 $base_uri->host($ENV{SERVER_NAME}); 17 $base_uri->port($ENV{SERVER_PORT}); 18 $base_uri->path($ENV{SCRIPT_NAME} . '/'); 19 13 20 my $dbname = 'new.db'; 14 21 my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", "", "", { RaiseError => 1 }); 15 22 my $bookmarks = Bookmarks->new({ 16 23 dbh => $dbh, 24 base_uri => $base_uri, 17 25 }); 18 26 … … 72 80 return decode_utf8( 73 81 encode_json({ 74 resources => \@resources,82 bookmarks => \@resources, 75 83 }) 76 84 ); … … 102 110 my $id = $self->param('id'); 103 111 my $field = $self->param('field'); 112 my $format = $self->query->param('format') || 'html'; 104 113 105 114 my $bookmark = $bookmarks->get_bookmark({ id => $id }); … … 114 123 return ref $value eq 'ARRAY' ? join(',', @{ $value }) : $value; 115 124 } else { 116 # display the bookmark form for this bookmark 117 $bookmark->{exists} = 1; 118 $bookmark->{created} = "Created " . localtime($bookmark->{ctime}); 119 $bookmark->{created} .= '; Updated ' . localtime($bookmark->{mtime}) unless $bookmark->{ctime} == $bookmark->{mtime}; 120 $self->header_props( 121 -type => 'text/html', 122 -charset => 'UTF-8', 123 ); 124 return $self->tt_process( 125 'bookmark.tt', 126 $bookmark, 127 ); 125 if ($format eq 'json') { 126 $self->header_props( 127 -type => 'application/json', 128 -charset => 'UTF-8', 129 ); 130 return decode_utf8(encode_json($bookmark)); 131 } else { 132 # display the bookmark form for this bookmark 133 $bookmark->{exists} = 1; 134 $bookmark->{created} = "Created " . localtime($bookmark->{ctime}); 135 $bookmark->{created} .= '; Updated ' . localtime($bookmark->{mtime}) unless $bookmark->{ctime} == $bookmark->{mtime}; 136 $self->header_props( 137 -type => 'text/html', 138 -charset => 'UTF-8', 139 ); 140 return $self->tt_process( 141 'bookmark.tt', 142 $bookmark, 143 ); 144 } 128 145 } 129 146 } else { -
trunk/Bookmarks.pm
r2 r7 4 4 use Bookmark; 5 5 6 has dbh => ( is => 'ro'); 6 has dbh => ( is => 'ro' ); 7 has base_uri => ( is => 'ro' ); 7 8 8 9 sub get_bookmark { … … 24 25 $sth_tag->execute($bookmark->{uri}); 25 26 $bookmark->{tags} = [ map { $$_[0] } @{ $sth_tag->fetchall_arrayref } ]; 27 if ($self->base_uri) { 28 $bookmark->{bookmark_uri} = $self->base_uri . $bookmark->{id}; 29 } 26 30 } 27 31 return $bookmark; … … 46 50 $sth_tag->execute($resource->{uri}); 47 51 $resource->{tags} = [ map { $$_[0] } @{ $sth_tag->fetchall_arrayref } ]; 52 if ($self->base_uri) { 53 $resource->{bookmark_uri} = $self->base_uri . $resource->{id}; 54 } 48 55 push @resources, $resource; 49 56 }
Note: See TracChangeset
for help on using the changeset viewer.