Set the application class' %INC entry to something useful
[catagits/Web-Simple.git] / lib / Web / Simple.pm
index 697bb62..ad0a621 100644 (file)
@@ -5,12 +5,13 @@ use warnings::illegalproto ();
 use Moo ();
 use Web::Dispatch::Wrapper ();
 
-our $VERSION = '0.027';
+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;
@@ -18,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 };
@@ -26,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;
@@ -121,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