#!/usr/bin/perl # $AFresh1: todo.cgi,v 1.10 2010/02/02 17:03:42 andrew Exp $ ######################################################################## # todo.cgi *** REST CGI Handler for todo.txt files # # 2010.01.17 #*#*# andrew fresh ######################################################################## # Copyright 2010 Andrew Fresh, all rights reserved # # This program is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. ######################################################################## use strict; use warnings; use CGI; use lib 'lib'; use Text::Todo::REST::API; my $q = CGI->new(); my $api; eval { $api = Text::Todo::REST::API->new( { todo_dir => '/users/andrew/todo', default_format => 'text', } ); }; if ($@) { print "Error: $@\n"; exit 1; } my $method = $q->request_method or die 'REQUEST_METHOD required'; my $response; eval { ($response) = $api->$method( $q->path_info, $q->Vars ) }; if ($@) { print "Error: $@\n"; exit 2; } if ($response) { print $q->header($response->content_type); print $response->render(); } else { print $q->header(), $q->start_html; print $q->h1("Unknown ERROR!"); print $q->end_html; }