File: | lib/Railsish.pm |
Coverage: | 92.5% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Railsish; | ||||||
2 | # ABSTRACT: A web application framework. | ||||||
3 | |||||||
4 | 2 2 2 | 17 4 18 | use strict; | ||||
5 | 2 2 2 | 18 5 13 | use warnings; | ||||
6 | |||||||
7 | 2 2 2 | 85 6 35 | use HTTP::Engine::Response; | ||||
8 | 2 2 2 | 161 8 37 | use UNIVERSAL::require; | ||||
9 | |||||||
10 | my $app_package; | ||||||
11 | |||||||
12 | sub import { | ||||||
13 | 2 | 11 | $app_package = caller; | ||||
14 | |||||||
15 | 2 2 2 | 21 6 13 | no strict; | ||||
16 | 2 | 9 | for (qw(handle_request)) { | ||||
17 | 2 2 | 10 33 | *{"$app_package\::$_"} = \&$_; | ||||
18 | } | ||||||
19 | } | ||||||
20 | |||||||
21 | sub handle_request { | ||||||
22 | 1 | 0 | 3 | my $request = shift; | |||
23 | 1 | 14 | my $response = HTTP::Engine::Response->new; | ||||
24 | |||||||
25 | 1 | 8 | my $path = $request->request_uri; | ||||
26 | |||||||
27 | 1 | 11 | my ($controller) = $path =~ m{^/(\w+)}s; | ||||
28 | 1 | 8 | $controller ||= 'welcome'; | ||||
29 | |||||||
30 | 1 | 9 | my $controller_class = $app_package . "::" . ucfirst($controller) . "Controller"; | ||||
31 | 1 | 14 | $controller_class->require or die $@; | ||||
32 | |||||||
33 | 1 | 48 | $controller_class->dispatch($request, $response); | ||||
34 | |||||||
35 | 1 | 8 | return $response; | ||||
36 | } | ||||||
37 | |||||||
38 | 1; | ||||||
39 | |||||||
40 - 48 | =head1 DESCRIPTION This is a web app framework that is still very experimental. =head1 EXAMPLE At this moment, see t/SimpleApp for how to use this web framework. =cut | ||||||
49 |