Permalink
Browse files

a couple of cosmetic changes for dsl->dancer_version and register_plugin

  • Loading branch information...
1 parent 938bace commit e4cbca96403d940c268c54a759e21009d9cd5a87 Alexis Sukrieh committed Mar 27, 2012
Showing with 35 additions and 10 deletions.
  1. +1 −1 lib/Dancer.pm
  2. +2 −0 lib/Dancer/Core/DSL.pm
  3. +19 −9 lib/Dancer/Plugin.pm
  4. +1 −0 t/dsl.t
  5. +12 −0 t/plugin_register.t
View
@@ -10,7 +10,7 @@ use Dancer::Core::App;
use Dancer::Core::DSL;
use Dancer::FileUtils;
-our $VERSION = '1.9999_01';
+our $VERSION = '2.000000_01';
our $AUTHORITY = 'SUKRIA';
#
View
@@ -25,6 +25,7 @@ sub dsl_keywords {
[core_debug => 1],
[dance => 1],
[dancer_app => 1],
+ [dancer_version => 1],
[debug => 1],
[del => 1],
[dirname => 1],
@@ -83,6 +84,7 @@ sub dsl_keywords_as_list {
}
sub dancer_app { shift->app }
+sub dancer_version { (split /\./, $Dancer::VERSION)[0] }
sub dsl { shift }
sub debug { shift->log(debug => @_) }
View
@@ -3,11 +3,6 @@ use Moo::Role;
use Carp 'croak';
use Dancer::Core::DSL;
-# The plugin system major version, to check compatibility against it
-our $PLUGIN_MAJOR_VERSION = 2;
-
-sub major_version { $PLUGIN_MAJOR_VERSION }
-
sub _get_dsl {
my $dsl;
my $deep = 2;
@@ -99,6 +94,16 @@ sub register {
];
}
+=method register_plugin
+
+A Dancer plugin must end with this statement. This lets the plugin register all
+the symbols define with C<register> as exported symbols (via the L<Exporter>
+module).
+
+A Dancer plugin inherits from Dancer::Plugin and Exporter transparently.
+
+=cut
+
sub register_plugin {
my $plugin = caller;
my $caller = caller(1);
@@ -110,13 +115,18 @@ sub register_plugin {
my $supported_versions = $params{for_versions} || [ 1 ];
ref $supported_versions eq 'ARRAY'
- or croak "register_plugin must be called like this : register_plugin for_versions => [ 1, 2 ]";
-
- +{ map { $_ => 1 } @$supported_versions }->{$PLUGIN_MAJOR_VERSION}
- or croak "can't register plugin '$plugin', it doesn't support Dancer version $PLUGIN_MAJOR_VERSION, it only supports these version(s): " . join(',', @$supported_versions) . ". Please upgrade the plugin.";
+ or croak "register_plugin must be called with an array ref";
# if the caller has not a dsl, we cant register the plugin
return if ! $caller->can('dsl');
+ my $dancer_version = $caller->dsl->dancer_version;
+ my $plugin_version = eval "\$${plugin}::VERSION" || '??';
+
+ warn "supported_versions : ".join(', ', @$supported_versions);
+ # make sure the plugin is compatible with this version of Dancer
+ grep /^$dancer_version$/, @{ $supported_versions }
+ or croak "$plugin $plugin_version does not support Dancer $dancer_version.";
+
# we have a $dsl in our caller, we can register our symbols then
my $dsl = $caller->dsl;
View
@@ -19,4 +19,5 @@ any ['get', 'post'], '/' => sub {
is $r->[2][0], 'POST';
}
+is dancer_version, 2, 'dancer_version';
done_testing;
View
@@ -44,4 +44,16 @@ subtest 'plugin reserved keywords' => sub {
}
};
+subtest 'plugin version' => sub {
+
+ package Foo;
+ our $VERSION = '1.034';
+ use Dancer;
+ use Dancer::Plugin;
+
+ eval { register_plugin };
+ Test::More::like $@, qr{Foo 1.034 does not support Dancer 2};
+};
+
+
done_testing;

0 comments on commit e4cbca9

Please sign in to comment.