[Bps-public-commit] r14647 - in Path-Dispatcher/trunk: lib/Path/Dispatcher t

sartak at bestpractical.com sartak at bestpractical.com
Wed Jul 30 15:39:23 EDT 2008


Author: sartak
Date: Wed Jul 30 15:39:21 2008
New Revision: 14647

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
   Path-Dispatcher/trunk/t/100-declarative.t

Log:
 r68081 at onn:  sartak | 2008-07-30 15:39:14 -0400
 Figure out how sugar will be distributed


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm	Wed Jul 30 15:39:21 2008
@@ -3,14 +3,13 @@
 use strict;
 use warnings;
 use Sub::Exporter;
+use Path::Dispatcher;
 
 my $exporter = Sub::Exporter::build_exporter({
-    exports => {
-    },
+    into_level => 1,
     groups => {
-        default => [':all'],
+        default => \&build_sugar,
     },
-
 });
 
 sub import {
@@ -18,14 +17,26 @@
     my $pkg  = caller;
     my @args = grep { !/^-[Bb]ase/ } @_;
 
-    # they must have specified '-base' if there are no args
+    # they must have specified '-base' if there are a different number of args
     if (@args != @_) {
         no strict 'refs';
-        push @{ $pkg . '::ISA' }, $self
+        push @{ $pkg . '::ISA' }, $self;
     }
 
     $exporter->($self, @args);
 }
 
+sub build_sugar {
+    my ($class, $group, $arg) = @_;
+
+    my $dispatcher = Path::Dispatcher->new;
+
+    return {
+        dispatcher => sub { $dispatcher },
+        dispatch   => sub { $dispatcher->dispatch(@_) },
+        run        => sub { $dispatcher->run(@_) },
+    };
+}
+
 1;
 

Modified: Path-Dispatcher/trunk/t/100-declarative.t
==============================================================================
--- Path-Dispatcher/trunk/t/100-declarative.t	(original)
+++ Path-Dispatcher/trunk/t/100-declarative.t	Wed Jul 30 15:39:21 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 2;
+use Test::More tests => 4;
 
 do {
     package MyApp::Dispatcher;
@@ -9,6 +9,7 @@
 };
 
 ok(MyApp::Dispatcher->isa('Path::Dispatcher::Declarative'), "use Path::Dispatcher::Declarative -base sets up ISA");
+can_ok('MyApp::Dispatcher', qw/dispatcher dispatch run/);
 
 do {
     package MyApp::Dispatcher::NoBase;
@@ -16,4 +17,5 @@
 };
 
 ok(!MyApp::Dispatcher::NoBase->isa('Path::Dispatcher::Declarative'), "use Path::Dispatcher::Declarative without -base does not set up ISA");
+can_ok('MyApp::Dispatcher::NoBase', qw/dispatcher dispatch run/);
 



More information about the Bps-public-commit mailing list