package Web::Simple;
use strictures 1;
-use 5.008;
use warnings::illegalproto ();
use Moo ();
use Web::Dispatch::Wrapper ();
-our $VERSION = '0.026_001'; # TRIAL RELEASE
+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;
}
sub _export_into {
- my ($class, $app_package) = @_;
+ my ($class, $app_package, $app_file) = @_;
{
no strict 'refs';
*{"${app_package}::PSGI_ENV"} = sub () { -1 };
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;
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