Changeset 63 in bookmarks


Ignore:
Timestamp:
09/06/13 11:47:20 (11 years ago)
Author:
peter
Message:
  • renamed controller methods:
    • create --> create_and_redirect
    • edit --> update_and_redirect
  • use Moose instrospection instead of exception handling to determine if a requested field is available on a bookmark
  • removed a debugging response line
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BookmarkController.pm

    r62 r63  
    360360        return [304, [], []] if $self->_check_modified($bookmark->mtime); 
    361361 
     362        # check whether the requested field is part of the bookmark 
     363        if (!$bookmark->meta->has_attribute($field)) { 
     364            return [404, ['Content-Type' => 'text/plain; charset=UTF-8'], [qq{"$field" is not a valid bookmark data field}]]; 
     365        } 
     366 
    362367        # respond with just the requested field as plain text 
    363         my $value = eval { $bookmark->$field }; 
    364         if ($@) { 
    365             if ($@ =~ /Can't locate object method/) { 
    366                 return [404, ['Content-Type' => 'text/plain; charset=UTF-8'], [qq{"$field" is not a valid bookmark data field}]]; 
    367             } else { 
    368                 die $@; 
    369             } 
    370         } 
     368        my $value = $bookmark->$field; 
    371369        my $last_modified = time2str($bookmark->mtime); 
    372370        return [200, ['Content-Type' => 'text/plain; charset=UTF-8', 'Last-Modified' => $last_modified], [ref $value eq 'ARRAY' ? join(' ', @{ $value }) : $value]]; 
     
    376374} 
    377375 
    378 sub create { 
     376sub create_and_redirect { 
    379377    my $self = shift; 
    380378 
     
    393391} 
    394392 
    395 sub edit { 
     393sub update_and_redirect { 
    396394    my $self = shift; 
    397395    my $id = shift; 
  • trunk/app.psgi

    r61 r63  
    4848 
    4949            # create the bookmark and redirect to the new bookmark's edit form 
    50             return $controller->create; 
     50            return $controller->create_and_redirect; 
    5151        }; 
    5252    }; 
     
    8585            my $controller = get_controller($req); 
    8686 
    87             return $controller->edit($params->{id}); 
    88  
    89             return [200, ['Content-Type' => 'text/plain'], ['update ', $params->{id}]]; 
     87            return $controller->update_and_redirect($params->{id}); 
    9088        }; 
    9189    }; 
Note: See TracChangeset for help on using the changeset viewer.