Andy Baugh 2 éve
szülő
commit
48e8b2896b
5 módosított fájl, 28 hozzáadás és 10 törlés
  1. 4 0
      config/default.cfg
  2. 17 6
      lib/TCMS.pm
  3. 3 0
      lib/Trog/Config.pm
  4. 2 2
      lib/Trog/Routes/HTML.pm
  5. 2 2
      lib/Trog/Routes/JSON.pm

+ 4 - 0
config/default.cfg

@@ -1,3 +1,7 @@
 [general]
 data_model=FlatFile
 title=tCMS
+
+[routes]
+extra_modules=
+formats=HTML,RSS,XML,JSON

+ 17 - 6
lib/TCMS.pm

@@ -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();
 

+ 3 - 0
lib/Trog/Config.pm

@@ -3,6 +3,9 @@ package Trog::Config;
 use strict;
 use warnings;
 
+no warnings 'experimental';
+use feature qw{signatures};
+
 use Config::Tiny;
 
 =head1 Trog::Config

+ 2 - 2
lib/Trog/Routes/HTML.pm

@@ -40,7 +40,7 @@ our $footbar       = 'footbar.tx';
 
 # Note to maintainers: never ever remove backends from this list.
 # the auth => 1 is a crucial protection.
-our %routes = (
+use constant routes => {
     default => {
         callback => \&Trog::Routes::HTML::setup,
     },
@@ -163,7 +163,7 @@ our %routes = (
         callback => \&Trog::Routes::HTML::avatars,
         data     => { tag => ['about'] },
     },
-);
+};
 
 # Grab theme routes
 my $themed = 0;

+ 2 - 2
lib/Trog/Routes/JSON.pm

@@ -12,7 +12,7 @@ use Trog::Config();
 
 my $conf = Trog::Config::get();
 
-our %routes = (
+use constant routes => {
     '/api/catalog' => {
         method     => 'GET',
         callback   => \&catalog,
@@ -28,7 +28,7 @@ our %routes = (
         callback   => \&version,
         parameters => [],
     },
-);
+};
 
 # Clone / redact for catalog
 my $cloned = clone(\%routes);