=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm,v retrieving revision 1.1 retrieving revision 1.3 diff -u -r1.1 -r1.3 --- todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm 2010/02/18 05:34:31 1.1 +++ 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.5 2010/02/16 04:09:53 andrew Exp $ +# $AFresh1: PUT.pm,v 1.2 2010/02/18 06:25:09 andrew Exp $ use warnings; use strict; @@ -33,8 +33,6 @@ my ( $self, $todo, $options ) = @_; my $id = $options->{entry}; - use Data::Dumper; - print STDERR Dumper $options; my $new_text; VALUE: foreach my $k qw( text value ) { if ( exists $options->{$k} ) { @@ -63,33 +61,36 @@ $entry = $list->[ $id - 1 ]; } - if ($entry && $options->{md5}) { - warn md5_hex($entry->text) . '<>' . $options->{md5} . "($new_text)\n"; - 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 {