=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm 2010/02/18 06:25:09 1.2 +++ todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm 2010/02/23 05:03:58 1.3 @@ -1,6 +1,6 @@ package Text::Todo::REST::API::Actions::PUT; -# $AFresh1: PUT.pm,v 1.1 2010/02/18 05:34:31 andrew Exp $ +# $AFresh1: PUT.pm,v 1.2 2010/02/18 06:25:09 andrew Exp $ use warnings; use strict; @@ -61,32 +61,36 @@ $entry = $list->[ $id - 1 ]; } - if ($entry && $options->{md5}) { - if (md5_hex($entry->text) ne lc($options->{md5})) { - $entry = undef; - } + if (! $entry) { + return $self->_fail("Unable to find entry [$id]!"); } - if ( defined $new_text ) { - if ($entry) { - $entry->replace($new_text); - } - else { - $entry = $todo->add($new_text); - $line = 1 + @{$list}; - } + if ( $options->{md5} + && md5_hex( $entry->text ) ne lc( $options->{md5} ) ) + { + $self->_fail('MD5 Check Failed');#{ + #error => 501, + #name => 'MD5_Fail', + #message => 'MD5 Check Failed', + #}); + } - $todo->save; - - return { - line => $line, - md5 => md5_hex( $entry->text ), - text => $entry->text, - done => $entry->done, - }; + if ( $options->{oldText} + && $entry->text ne $options->{oldText} + ) { + $self->_fail('Old text check failed'); } - return $self->_fail("Unable to find entry [$id]!"); + $entry->replace($new_text); + + $todo->save; + + return { + line => $line, + md5 => md5_hex( $entry->text ), + text => $entry->text, + done => $entry->done, + }; } #sub put_list {