From: Karen Etheridge Date: Sun, 8 Sep 2013 21:03:48 +0000 (-0700) Subject: Class::MOP::load_class, is_class_loaded was deprecated in Moose-2.1100 X-Git-Tag: 5.90050~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e7399d8baa841cb6525daa2c20d88f70ba42474c;hp=71952d604a7cd31491639b7428331be7f70be46e Class::MOP::load_class, is_class_loaded was deprecated in Moose-2.1100 --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 4e39052..238537c 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -40,6 +40,7 @@ use Plack::Middleware::ReverseProxy; use Plack::Middleware::IIS6ScriptNameFix; use Plack::Middleware::IIS7KeepAliveFix; use Plack::Middleware::LighttpdScriptNameFix; +use Class::Load 'load_class'; BEGIN { require 5.008003; } @@ -2663,7 +2664,7 @@ sub setup_dispatcher { $dispatcher = $class->dispatcher_class; } - Class::MOP::load_class($dispatcher); + load_class($dispatcher); # dispatcher instance $class->dispatcher( $dispatcher->new ); @@ -2713,7 +2714,7 @@ sub setup_engine { # Don't really setup_engine -- see _setup_psgi_app for explanation. return if $class->loading_psgi_file; - Class::MOP::load_class($engine); + load_class($engine); if ($ENV{MOD_PERL}) { my $apache = $class->engine_loader->auto; @@ -2977,7 +2978,7 @@ the plugin name does not begin with C. my ( $proto, $plugin, $instant ) = @_; my $class = ref $proto || $proto; - Class::MOP::load_class( $plugin ); + load_class( $plugin ); $class->log->warn( "$plugin inherits from 'Catalyst::Component' - this is deprecated and will not work in 5.81" ) if $plugin->isa( 'Catalyst::Component' ); my $plugin_meta = Moose::Meta::Class->create($plugin); @@ -3025,7 +3026,7 @@ the plugin name does not begin with C. } @{ $plugins }; for my $plugin ( reverse @plugins ) { - Class::MOP::load_class($plugin->[0], $plugin->[1]); + load_class($plugin->[0], $plugin->[1]); my $meta = find_meta($plugin->[0]); next if $meta && $meta->isa('Moose::Meta::Role'); diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index f747099..bb2a201 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -9,6 +9,7 @@ use Devel::InnerPackage (); use MRO::Compat; use mro 'c3'; use Scalar::Util 'blessed'; +use Class::Load 'is_class_loaded'; use namespace::clean -except => 'meta'; with 'MooseX::Emulate::Class::Accessor::Fast'; @@ -93,7 +94,7 @@ sub BUILDARGS { } elsif (@_ == 2) { # is it ($app, $args) or foo => 'bar' ? if (blessed($_[0])) { $args = $_[1] if ref($_[1]) eq 'HASH'; - } elsif (Class::MOP::is_class_loaded($_[0]) && + } elsif (is_class_loaded($_[0]) && $_[0]->isa('Catalyst') && ref($_[1]) eq 'HASH') { $args = $_[1]; } else { diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index 10f290b..4228ff8 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -320,7 +320,7 @@ sub action_class { ? $args{attributes}{ActionClass}[0] : $self->_action_class); - Class::MOP::load_class($class); + load_class($class); return $class; } diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index d9fe5b3..6fde402 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -14,6 +14,7 @@ use Catalyst::Utils; use Text::SimpleTable; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; +use Class::Load qw(load_class try_load_class); use namespace::clean -except => 'meta'; @@ -516,7 +517,8 @@ sub register { unless ( $registered->{$class} ) { # FIXME - Some error checking and re-throwing needed here, as # we eat exceptions loading dispatch types. - eval { Class::MOP::load_class($class) }; + # see also try_load_class + eval { load_class($class) }; my $load_failed = $@; $self->_check_deprecated_dispatch_type( $key, $load_failed ); push( @{ $self->dispatch_types }, $class->new ) unless $load_failed; @@ -660,9 +662,8 @@ sub _load_dispatch_types { # first param is undef because we cannot get the appclass my $class = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $type); - eval { Class::MOP::load_class($class) }; - Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ ) - if $@; + my ($success, $error) = try_load_class($class); + Catalyst::Exception->throw( message => $error ) if not $success; push @{ $self->dispatch_types }, $class->new; push @loaded, $class; diff --git a/lib/Catalyst/Script/Create.pm b/lib/Catalyst/Script/Create.pm index 593323d..a74653b 100644 --- a/lib/Catalyst/Script/Create.pm +++ b/lib/Catalyst/Script/Create.pm @@ -1,5 +1,6 @@ package Catalyst::Script::Create; use Moose; +use Class::Load 'load_class'; use namespace::autoclean; with 'Catalyst::ScriptRole'; @@ -42,7 +43,7 @@ sub run { $self->print_usage_text if !$self->ARGV->[0]; my $helper_class = $self->helper_class; - Class::MOP::load_class($helper_class); + load_class($helper_class); my $helper = $helper_class->new( { '.newfiles' => !$self->force, mech => $self->mechanize } ); $self->print_usage_text unless $helper->mk_component( $self->application_name, @{$self->extra_argv} ); diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 270490e..1848e4a 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -1,7 +1,7 @@ package Catalyst::Script::Server; use Moose; use Catalyst::Utils; -use Try::Tiny; +use Class::Load qw(try_load_class load_class); use namespace::autoclean; with 'Catalyst::ScriptRole'; @@ -49,11 +49,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 +74,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; + my ($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); } @@ -229,7 +227,7 @@ sub run { return 1 unless $self->is_daemon; - Class::MOP::load_class($self->application_name); + load_class($self->application_name); $self->daemon_detach; } diff --git a/lib/Catalyst/ScriptRole.pm b/lib/Catalyst/ScriptRole.pm index 4bab785..f8a12da 100644 --- a/lib/Catalyst/ScriptRole.pm +++ b/lib/Catalyst/ScriptRole.pm @@ -5,6 +5,7 @@ use MooseX::Getopt; use Catalyst::EngineLoader; use Moose::Util::TypeConstraints; use Catalyst::Utils qw/ ensure_class_loaded /; +use Class::Load 'load_class'; use namespace::autoclean; subtype 'Catalyst::ScriptRole::LoadableClass', @@ -87,7 +88,7 @@ sub _plack_engine_name {} sub _run_application { my $self = shift; my $app = $self->application_name; - Class::MOP::load_class($app); + load_class($app); my $server; if (my $e = $self->_plack_engine_name ) { $server = $self->load_engine($e, $self->_plack_loader_args); diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 53c16a2..33602d6 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -7,7 +7,7 @@ use Test::More (); use Plack::Test; use Catalyst::Exception; use Catalyst::Utils; -use Class::MOP; +use Class::Load qw(load_class is_class_loaded); use Sub::Exporter; use Carp 'croak', 'carp'; @@ -25,7 +25,7 @@ sub _build_request_export { return sub { croak "Must specify a test app: use Catalyst::Test 'TestApp'" } unless $class; - Class::MOP::load_class($class) unless Class::MOP::is_class_loaded($class); + load_class($class) unless is_class_loaded($class); $class->import; return sub { _local_request( $class, @_ ) }; diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 245c789..76b8262 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -7,7 +7,7 @@ use Path::Class; use URI; use Carp qw/croak/; use Cwd; -use Class::MOP; +use Class::Load 'is_class_loaded'; use String::RewritePrefix; use namespace::clean; @@ -297,7 +297,7 @@ sub ensure_class_loaded { # if it already has symbol table entries. This is to support things like Schema::Loader, which # part-generate classes in memory, but then also load some of their contents from disk. return if !$opts->{ ignore_loaded } - && Class::MOP::is_class_loaded($class); # if a symbol entry exists we don't load again + && is_class_loaded($class); # if a symbol entry exists we don't load again # this hack is so we don't overwrite $@ if the load did not generate an error my $error; @@ -312,7 +312,7 @@ sub ensure_class_loaded { die $error if $error; warn "require $class was successful but the package is not defined." - unless Class::MOP::is_class_loaded($class); + unless is_class_loaded($class); return 1; } diff --git a/t/aggregate/caf_backcompat.t b/t/aggregate/caf_backcompat.t index 0523134..ddff5f6 100644 --- a/t/aggregate/caf_backcompat.t +++ b/t/aggregate/caf_backcompat.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::More; -use Class::MOP (); +use Class::Load 'load_class'; use Moose::Util (); # List of everything which used Class::Accessor::Fast in 5.70. @@ -21,7 +21,7 @@ my @modules = qw/ plan tests => scalar @modules; foreach my $module (@modules) { - Class::MOP::load_class($module); + load_class($module); ok Moose::Util::does_role($module => 'MooseX::Emulate::Class::Accessor::Fast'), "$module has Class::Accessor::Fast back-compat"; } diff --git a/t/lib/Catalyst/Plugin/Test/MangleDollarUnderScore.pm b/t/lib/Catalyst/Plugin/Test/MangleDollarUnderScore.pm index 94a5184..32c304d 100644 --- a/t/lib/Catalyst/Plugin/Test/MangleDollarUnderScore.pm +++ b/t/lib/Catalyst/Plugin/Test/MangleDollarUnderScore.pm @@ -2,11 +2,12 @@ package Catalyst::Plugin::Test::MangleDollarUnderScore; use strict; use warnings; +# FIXME - should proably use utf8?? our $VERSION = 0.1; # Make is_class_loaded happy -# Class::MOP::load_class($_) can hurt you real hard. +# Class::Load::load_class($_) can hurt you real hard. BEGIN { $_ = q{ -mst sayeth, Class::MOP::load_class($_) will ruin your life +mst sayeth, Class::Load::load_class($_) will ruin your life rafl spokeh "i ♥ my $_"', and verrily forsooth, t0m made tests and yea, there was fail' }; } diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index b06880c..bb88a73 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -11,6 +11,7 @@ use Catalyst qw/ +TestApp::Role /; use Catalyst::Utils; +use Class::Load 'try_load_class'; use Moose; use namespace::autoclean; @@ -59,7 +60,7 @@ TestApp->config( # above ->setup so we have some generated methods to be double sure. has an_attribute_before_we_change_base_classes => ( is => 'ro'); -if ($::setup_leakchecker && eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) { +if ($::setup_leakchecker && try_load_class('CatalystX::LeakChecker')) { with 'CatalystX::LeakChecker'; has leaks => ( diff --git a/t/unit_utils_load_class.t b/t/unit_utils_load_class.t index 6712f67..47994c5 100644 --- a/t/unit_utils_load_class.t +++ b/t/unit_utils_load_class.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 18; -use Class::MOP; +use Class::Load 'is_class_loaded'; use lib "t/lib"; @@ -19,11 +19,11 @@ $SIG{__WARN__} = sub { $warnings++; }; -ok( !Class::MOP::is_class_loaded("TestApp::View::Dump"), "component not yet loaded" ); +ok( !is_class_loaded("TestApp::View::Dump"), "component not yet loaded" ); Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump"); -ok( Class::MOP::is_class_loaded("TestApp::View::Dump"), "loaded ok" ); +ok( is_class_loaded("TestApp::View::Dump"), "loaded ok" ); is( $warnings, 0, "no warnings emitted" ); $warnings = 0; @@ -31,10 +31,10 @@ $warnings = 0; Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump"); is( $warnings, 0, "calling again doesn't reaload" ); -ok( !Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" ); +ok( !is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" ); Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request"); -ok( Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" ); +ok( is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" ); is( $warnings, 0, "calling again doesn't reaload" );