[BACK]Return to todo.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 / Attic / todo.cgi (download)

Revision 1.7, Tue Jan 26 06:02:29 2010 UTC (14 years, 5 months ago) by andrew
Branch: MAIN
Changes since 1.6: +6 -4 lines

Use the new $response = $api->$method($path, $args) format.

#!/usr/bin/perl
# $AFresh1: todo.cgi,v 1.7 2010/01/26 06:02:29 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 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 = $ENV{HTTP_METHOD} || 'GET';

my $response;
eval { $response = $api->$method( $ENV{PATH_INFO}, $q->Vars ) };
if ($@) {
    print "Error: $@\n";
    exit 2;
}
print $q->header($response->content_type);
print $response->render();