|
|
@@ -21,7 +21,6 @@ use Time::HiRes qw{gettimeofday tv_interval};
|
|
|
use HTTP::Parser::XS qw{HEADERS_AS_HASHREF};
|
|
|
use List::Util;
|
|
|
|
|
|
-#Grab our custom routes
|
|
|
use lib 'lib';
|
|
|
use Trog::Routes::HTML;
|
|
|
use Trog::Routes::JSON;
|
|
|
@@ -34,15 +33,27 @@ use Trog::Vars;
|
|
|
|
|
|
# Troglodyne philosophy - simple as possible
|
|
|
|
|
|
-# Import the routes
|
|
|
+# Import the routes. Made extensible by the 'extra_modules' param in config.
|
|
|
+# Just add another module in lib/Trog/Routes/ and specify it in config.
|
|
|
|
|
|
my $conf = Trog::Config::get();
|
|
|
my $data = Trog::Data->new($conf);
|
|
|
-my %roots = $data->routes();
|
|
|
|
|
|
-my %routes = %Trog::Routes::HTML::routes;
|
|
|
-@routes{keys(%Trog::Routes::JSON::routes)} = values(%Trog::Routes::JSON::routes);
|
|
|
-@routes{keys(%roots)} = values(%roots);
|
|
|
+my %routes;
|
|
|
+my @required_modules = qw{HTML JSON Formatted};
|
|
|
+foreach my $route_module (@required_modules, split( /,/, $conf->{'routes'}{'extra_modules'} || '' )) {
|
|
|
+ my $ns = "Trog::Routes::$route_module";
|
|
|
+ eval "require $ns";
|
|
|
+ if($@) {
|
|
|
+ warn "Error when loading $ns: $@";
|
|
|
+ next;
|
|
|
+ }
|
|
|
+ @routes{keys(%{$ns->routes()} = values(%{$ns->routes()});
|
|
|
+}
|
|
|
+{
|
|
|
+ my %roots = $data->routes();
|
|
|
+ @routes{keys(%roots)} = values(%roots);
|
|
|
+}
|
|
|
|
|
|
my %aliases = $data->aliases();
|
|
|
|