Fix ensure_class_loaded in Catalyst::ScriptRole
Andrew Rodland [Sun, 19 Mar 2017 20:07:02 +0000 (16:07 -0400)]
it was trying to import ensure_class_loaded from Catalyst::Utils, but
Catalyst::Utils doesn't export. On current perls the import silently
fails, and the coercion for loader_class would have failed at runtime
if anyone actually tried to pass a non-loaded class as loader_class.
But with a sufficiently old version of UNIVERSAL it fails at compile
time instead (http://stackoverflow.com/q/42883017). Also the return
value of the via was 1, so no one could have ever been using this
thing. Fix it up.

While we're there, replace a usage of Class::Load::load_class with
ensure_class_loaded, because we don't really need two.

lib/Catalyst/ScriptRole.pm

index f8a12da..845e891 100644 (file)
@@ -4,15 +4,14 @@ use Pod::Usage;
 use MooseX::Getopt;
 use Catalyst::EngineLoader;
 use Moose::Util::TypeConstraints;
-use Catalyst::Utils qw/ ensure_class_loaded /;
-use Class::Load 'load_class';
+use Catalyst::Utils;
 use namespace::autoclean;
 
 subtype 'Catalyst::ScriptRole::LoadableClass',
   as 'ClassName';
 coerce 'Catalyst::ScriptRole::LoadableClass',
   from 'Str',
-  via { ensure_class_loaded($_); 1 };
+  via { Catalyst::Utils::ensure_class_loaded($_); $_ };
 
 with 'MooseX::Getopt' => {
     -version => 0.48,
@@ -88,7 +87,7 @@ sub _plack_engine_name {}
 sub _run_application {
     my $self = shift;
     my $app = $self->application_name;
-    load_class($app);
+    Catalyst::Utils::ensure_class_loaded($app);
     my $server;
     if (my $e = $self->_plack_engine_name ) {
         $server = $self->load_engine($e, $self->_plack_loader_args);