[BACK]Return to todo-rest.cgi CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo-REST-API / example / cgi-bin

File: [local] / todotxt / Text-Todo-REST-API / example / cgi-bin / todo-rest.cgi (download)

Revision 1.2, Tue Feb 23 05:03:23 2010 UTC (14 years, 3 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -3 lines

no more Dumper

#!/usr/bin/perl
# $AFresh1: todo-rest.cgi,v 1.2 2010/02/23 05:03:23 andrew Exp $
########################################################################
# todo.cgi *** REST CGI Handler for todo.txt files
#
# 2010.01.17 #*#*# andrew fresh <andrew@cpan.org>
########################################################################
# 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->param('_method') || 
	$q->request_method or die 'REQUEST_METHOD required';

$method = uc($method);

my $response;
warn "$api -> $method ( " . $q->path_info . ", " . $q->Vars . ")\n";
eval { ($response) = $api->$method( $q->path_info, scalar $q->Vars ) };
if ($@) {
    warn "Error: $@\n";

    print $q->header(), $q->start_html;
    print "Error: $@\n";
    print $q->end_html;
    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;
}