Changeset 112 in bookmarks for trunk/lib/Bookmarks/List.pm


Ignore:
Timestamp:
02/17/16 22:05:50 (8 years ago)
Author:
peter
Message:
  • Added the sidebar resource.
  • Moved the list resources to list.
  • Respond with a 406 if the required modules are not available for XBEL, Atom, or CSV.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Bookmarks/List.pm

    r106 r112  
    3232            text => 'JSON', 
    3333            type => 'application/json', 
     34            path => 'list', 
    3435            query => { 
    3536                %$query, 
     
    4041            text => 'XBEL', 
    4142            type => 'application/xml', 
     43            path => 'list', 
    4244            query => { 
    4345                %$query, 
     
    5658            text => 'CSV', 
    5759            type => 'text/csv', 
     60            path => 'list', 
    5861            query => { 
    5962                %$query, 
     
    6467            text => 'URI List', 
    6568            type => 'text/uri-list', 
     69            path => 'list', 
    6670            query => { 
    6771                %$query, 
     
    7276            text => 'HTML', 
    7377            type => 'text/html', 
     78            path => 'list', 
    7479            query => { 
    7580                %$query, 
     
    105110sub as_xbel { 
    106111    my $self = shift; 
    107     require XML::XBEL; 
    108     #TODO: conditional support; if XML::XBEL is not present, return a 5xx response 
     112 
     113    eval { require XML::XBEL; } or 
     114        return [406, ['Content-Type' => 'text/plain'], ['This server does not support XBEL lists']]; 
    109115 
    110116    my $xbel = XML::XBEL->new; 
     
    147153sub as_csv { 
    148154    my $self = shift; 
    149     require Text::CSV::Encoded; 
     155 
     156    eval { require Text::CSV::Encoded } or 
     157        return [406, ['Content-Type' => 'text/plain'], ['This server does not support CSV lists']]; 
     158 
    150159    my $csv = Text::CSV::Encoded->new({ encoding_out => 'utf8' }); 
    151160    my $text = qq{id,uri,title,tags,ctime,mtime\n}; 
     
    182191    my $template = Template->new({ INCLUDE_PATH => File::Basename::dirname($INC{'Bookmarks/List.pm'}) }); 
    183192 
    184     my @all_tags = $self->bookmarks->get_tags({ selected => @{ $self->tags }[0] }); 
    185     my @cotags = $self->bookmarks->get_cotags({ search => $self->search }); 
    186  
    187193    $template->process( 
    188         'list.tt', 
     194        'html_list.tt', 
    189195        { 
    190196            base_url     => $self->bookmarks->base_uri, 
    191197            title        => $self->title, 
    192198            query        => $self->query, 
    193             selected_tag => @{ $self->tags }[0], 
    194             search_tags  => $self->tags, 
    195199            links        => [ $self->_get_list_links('text/html', { q => $self->query, tag => $self->tags }) ], 
    196             all_tags     => \@all_tags, 
    197             cotags       => \@cotags, 
    198200            resources    => $self->results, 
    199201            pages        => $self->search->pages, 
     
    207209    my $self = shift; 
    208210 
    209     require XML::Atom; 
     211    eval { require XML::Atom } or 
     212        return [406, ['Content-Type' => 'text/plain'], ['This server does not support Atom lists']]; 
     213 
    210214    $XML::Atom::DefaultVersion = "1.0"; 
    211215 
Note: See TracChangeset for help on using the changeset viewer.