use strict; use CGI '3.30', (); my $q = CGI->new; sub GET($$) { my ($path, $code) = @_; return unless $q->request_method eq 'GET' or $q->request_method eq 'HEAD'; return unless $q->path_info =~ $path; $code->(); exit; } eval { GET qr{^/=$} => sub { print $q->header('text/html'); print $q->h1('REST API Documentation'); }; GET qr{^/=/model/book/id/([\d-]+)$} => sub { my $id = $1; # Look up the resource file my $filename = get_local_path($id); if (-f $filename) { .. }; }; }; if( $@ ) { print "There was an error."; };