Changeset 88 in bookmarks for trunk


Ignore:
Timestamp:
06/04/15 22:00:25 (9 years ago)
Author:
peter
Message:

Better separation of the model for searching and the web app controller/representation layer

  • renamed Bookmarks::get_bookmarks() to search()
  • Bookmarks::search() now returns a Bookmarks::Search object instead of a Bookmarks::List
  • search results now reside in the Bookmarks::Search class
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bkmk

    r87 r88  
    4646    list => sub { 
    4747        my @tags = @_; 
    48         my $resources = $bookmarks->get_bookmarks({ 
     48        my $resources = $bookmarks->search({ 
    4949            tags => \@tags 
    5050        }); 
     
    7777    dump => sub { 
    7878        my ($dump_file) = @_; 
    79         my $dump = [ map { $_->TO_JSON } @{ $bookmarks->get_bookmarks->results } ]; 
     79        my $dump = [ map { $_->TO_JSON } @{ $bookmarks->search->results } ]; 
    8080        $dump_file ? YAML::DumpFile($dump_file, $dump) : print Dump($dump); 
    8181    }, 
  • trunk/lib/Bookmarks.pm

    r84 r88  
    77 
    88use Bookmark; 
    9 use Bookmarks::List; 
    109use Bookmarks::Search; 
    1110 
     
    10099} 
    101100 
    102 sub get_bookmarks { 
     101sub search { 
    103102    my $self = shift; 
    104103    my $params = shift || {}; 
     
    130129        }); 
    131130    } 
    132     return Bookmarks::List->new({ 
    133         bookmarks => $self, 
    134         search    => $search, 
    135         results   => \@resources, 
    136     }); 
     131    $search->results(\@resources); 
     132 
     133    return $search; 
    137134} 
    138135 
  • trunk/lib/Bookmarks/Controller.pm

    r75 r88  
    77use JSON; 
    88use Bookmarks; 
     9use Bookmarks::List; 
    910use URI; 
    1011use Template; 
     
    8384    my $offset = $self->request->param('offset'); 
    8485 
    85     my $list = $self->bookmarks->get_bookmarks({ 
    86         query  => $query, 
    87         tags   => \@tags, 
    88         limit  => $limit, 
    89         offset => $offset, 
     86    my $list = Bookmarks::List->new({ 
     87        bookmarks => $self->bookmarks, 
     88        search    => $self->bookmarks->search({ 
     89            query  => $query, 
     90            tags   => \@tags, 
     91            limit  => $limit, 
     92            offset => $offset, 
     93        }), 
    9094    }); 
    9195 
     
    104108 
    105109    # construct a feed from the most recent 12 bookmarks 
    106     my $list = $self->bookmarks->get_bookmarks({ query => $query, tags => \@tags, limit => 12 }); 
     110    my $list = Bookmarks::List->new({ 
     111        bookmarks => $self->bookmarks, 
     112        search    => $self->bookmarks->search({ query => $query, tags => \@tags, limit => 12 }), 
     113    }); 
    107114    return $list->as_atom; 
    108115} 
  • trunk/lib/Bookmarks/List.pm

    r71 r88  
    1313    is => 'ro', 
    1414    isa => 'Bookmarks::Search', 
    15     handles => [qw{query tags limit offset}], 
     15    handles => [qw{query tags limit offset results}], 
    1616); 
    17 has results => ( is => 'ro' ); 
    1817has title => ( 
    1918    is => 'ro', 
  • trunk/lib/Bookmarks/Search.pm

    r71 r88  
    1111has offset => (is => 'ro'); 
    1212 
     13has results => (is => 'rw', default => sub { [] }); 
     14 
    1315# module return 
    14161; 
  • trunk/scan

    r72 r88  
    2525my $csv = Text::CSV->new; 
    2626 
    27 for my $bookmark (@{ $bookmarks->get_bookmarks->results }) { 
     27for my $bookmark (@{ $bookmarks->search->results }) { 
    2828    printf "%3d %s\n", $bookmark->id, $bookmark->uri unless $CSV; 
    2929    my $response = $ua->head($bookmark->uri); 
Note: See TracChangeset for help on using the changeset viewer.