Set the application class' %INC entry to something useful
[catagits/Web-Simple.git] / lib / Web / Simple.pm
index 2959bce..ad0a621 100644 (file)
@@ -1,17 +1,17 @@
 package Web::Simple;
 
 use strictures 1;
-use 5.008;
 use warnings::illegalproto ();
 use Moo ();
 use Web::Dispatch::Wrapper ();
 
-our $VERSION = '0.020';
+our $VERSION = '0.028';
 
 sub import {
   my ($class, $app_package) = @_;
-  $app_package ||= caller;
-  $class->_export_into($app_package);
+  my ($caller_package, $caller_file) = caller;
+  $app_package ||= $caller_package;
+  $class->_export_into($app_package, $caller_file);
   eval "package $app_package; use Web::Dispatch::Wrapper; use Moo; 1"
     or die "Failed to setup app package: $@";
   strictures->import;
@@ -19,7 +19,7 @@ sub import {
 }
 
 sub _export_into {
-  my ($class, $app_package) = @_;
+  my ($class, $app_package, $app_file) = @_;
   {
     no strict 'refs';
     *{"${app_package}::PSGI_ENV"} = sub () { -1 };
@@ -27,7 +27,7 @@ sub _export_into {
     unshift(@{"${app_package}::ISA"}, 'Web::Simple::Application');
   }
   (my $name = $app_package) =~ s/::/\//g;
-  $INC{"${name}.pm"} = 'Set by "use Web::Simple;" invocation';
+  $INC{"${name}.pm"} ||= $app_file || 'Set by "use Web::Simple;" invocation';
 }
 
 1;
@@ -122,15 +122,14 @@ It also exports the following subroutines for use in dispatchers:
 
   redispatch_to '/somewhere';
 
-Finally, import sets
-
-  $INC{"NameOfApplication.pm"} = 'Set by "use Web::Simple;" invocation';
-
-so that perl will not attempt to load the application again even if
+Finally, import ensures that C<$INC{"NameOfApplication.pm"}> is set so that
+perl will not attempt to load the application again even if
 
   require NameOfApplication;
 
-is encountered in other code.
+is encountered in other code.  If the C<%INC> entry isn't already set by the
+time import is called, it's set to the caller's file or, failing that, the
+string C<Set by "use Web::Simple;" invocation>.
 
 One important thing to remember when using
 
@@ -517,9 +516,9 @@ would write:
   sub (?page=&order_by~) {
     my ($self, $page, $order_by) = @_;
     return unless $page =~ /^\d+$/;
-    $page ||= 'id';
+    $order_by ||= 'id';
     response_filter {
-      $_[1]->search_rs({}, $p);
+      $_[1]->search_rs({}, { page => $page, order_by => $order_by });
     }
   }