Changeset 9 in bookmarks for trunk/BookmarkApp.pm


Ignore:
Timestamp:
03/25/12 15:45:11 (12 years ago)
Author:
peter
Message:
  • use SQL::Interp to generate the SQL for Bookmarks::get_resources()
  • Bookmarks::get_resources() accepts a limit parameter to add a limit to the SQL query
  • added a feed run mode that returns an Atom feed of the most recent 12 bookmarks; can have an optional ?tag parameter that only looks for bookmarks with that tag
  • added an explicit "list" dispatch target that calls the `list run mode
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BookmarkApp.pm

    r8 r9  
    3030    $self->run_modes([qw{ 
    3131        list 
     32        feed 
    3233        view 
    3334        edit 
     
    104105        ); 
    105106    } 
     107} 
     108 
     109sub feed { 
     110    my $self = shift; 
     111    my $q = $self->query; 
     112 
     113    my $tag = $q->param('tag'); 
     114 
     115    require XML::Atom::Feed; 
     116    require XML::Atom::Entry; 
     117    require XML::Atom::Link; 
     118 
     119    my $feed = XML::Atom::Feed->new; 
     120    $feed->title('Bookmarks'); 
     121    $feed->id($base_uri . 'feed'); 
     122 
     123    # construct a feed from the most recent 12 bookmarks 
     124    for my $bookmark ($bookmarks->get_resources({ tag => $tag, limit => 12 })) { 
     125        my $entry = XML::Atom::Entry->new; 
     126        $entry->id($bookmark->{bookmark_uri}); 
     127        $entry->title($bookmark->{title}); 
     128        my $link = XML::Atom::Link->new; 
     129        $link->href($bookmark->{uri}); 
     130        $entry->add_link($link); 
     131        $entry->summary('Tags: ' . join(', ', @{ $bookmark->{tags} })); 
     132        $feed->add_entry($entry); 
     133    } 
     134 
     135    $self->header_props( 
     136        -type => 'application/atom+xml', 
     137        -charset => 'UTF-8', 
     138    ); 
     139    return $feed->as_xml; 
    106140} 
    107141 
Note: See TracChangeset for help on using the changeset viewer.