You can reduce your script to a minimal example for learning:
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.";
};
Each call to GET gets passed a regular expression and a piece of code to call. The GET routine will then check whether
the request matches that regular expression and if it does, call the callback to produce the result.
All of this is not related to the CGI module at all, except for where the request comes from.
To familiarize yourself with the code, I would start with (a copy of) the program and rip out as much of CGI as possible and run it from the command line. Add print statements to see where the code goes through and what it looks at.