drop namespace::autoclean
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / Server.pm
index 270490e..6c859b9 100644 (file)
@@ -1,8 +1,8 @@
 package Catalyst::Script::Server;
 use Moose;
 use Catalyst::Utils;
-use Try::Tiny;
-use namespace::autoclean;
+use Class::Load qw(try_load_class load_class);
+use namespace::clean -except => [ 'meta' ];
 
 with 'Catalyst::ScriptRole';
 
@@ -37,6 +37,7 @@ has port => (
     cmd_aliases   => 'p',
     isa           => 'Int',
     is            => 'ro',
+    lazy          => 1,
     default       => sub {
         Catalyst::Utils::env_value(shift->application_name, 'port') || 3000
     },
@@ -49,11 +50,9 @@ subtype 'Catalyst::Script::Server::Types::Pidfile',
     as 'MooseX::Daemonize::Pid::File';
 
 coerce 'Catalyst::Script::Server::Types::Pidfile', from 'Str', via {
-    try { Class::MOP::load_class("MooseX::Daemonize::Pid::File") }
-    catch {
-        warn("Could not load MooseX::Daemonize::Pid::File, needed for --pid option\n");
-        exit 1;
-    };
+    my ($success, $error) = try_load_class("MooseX::Daemonize::Pid::File");
+    warn("Could not load MooseX::Daemonize::Pid::File, needed for --pid option: $error\n"),
+        exit 1 if not $success;
     MooseX::Daemonize::Pid::File->new( file => $_ );
 };
 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
@@ -76,11 +75,11 @@ sub BUILD {
 
     if ($self->background) {
         # FIXME - This is evil. Should we just add MX::Daemonize to the deps?
-        try { Class::MOP::load_class('MooseX::Daemonize::Core'); Class::MOP::load_class('POSIX') }
-        catch {
-            warn("MooseX::Daemonize is needed for the --background option\n");
-            exit 1;
-        };
+        my ($success, $error) = try_load_class("MooseX::Daemonize::Core");
+        warn("MooseX::Daemonize is needed for the --background option: $error\n"),
+            exit 1 if not $success;
+        ($success, $error) = try_load_class("POSIX");
+        warn("$error\n"), exit 1 if not $success;
         MooseX::Daemonize::Core->meta->apply($self);
         POSIX::close($_) foreach (0..2);
     }
@@ -109,6 +108,7 @@ has restart => (
     cmd_aliases   => 'r',
     isa           => 'Bool',
     is            => 'ro',
+    lazy          => 1,
     default       => sub {
         Catalyst::Utils::env_value(shift->application_name, 'reload') || 0;
     },
@@ -229,7 +229,7 @@ sub run {
 
             return 1 unless $self->is_daemon;
 
-            Class::MOP::load_class($self->application_name);
+            load_class($self->application_name);
 
             $self->daemon_detach;
         }