From: Dave Rolsky Date: Mon, 1 Aug 2011 01:30:37 +0000 (-0500) Subject: Remove all uses of CMOP::{load_class, is_class_loaded, load_first_existing_class... X-Git-Tag: 2.0300~90 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5ae7c005663a1efb5ea4e89ecae184f96569305;p=gitmo%2FMoose.git Remove all uses of CMOP::{load_class, is_class_loaded, load_first_existing_class} and use Class::Load instead. Still need to deprecate the functions themselves and remove the tests for them. --- diff --git a/inc/RequireAuthorDeps.pm b/inc/RequireAuthorDeps.pm index d19966f..0a0beed 100644 --- a/inc/RequireAuthorDeps.pm +++ b/inc/RequireAuthorDeps.pm @@ -1,5 +1,6 @@ package inc::RequireAuthorDeps; +use Class::Load qw(load_class); use Moose; use Try::Tiny; @@ -18,7 +19,7 @@ sub before_release { } for my $mod (grep { $_ ne 'perl' } $req->required_modules) { - Class::MOP::load_class($mod); + load_class($mod); } } diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 1482ade..365d3af 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -11,6 +11,7 @@ use Class::MOP::Method::Constructor; use Class::MOP::MiniTrait; use Carp 'confess'; +use Class::Load 'is_class_loaded', 'load_class'; use Scalar::Util 'blessed', 'reftype', 'weaken'; use Sub::Name 'subname'; use Try::Tiny; @@ -1333,7 +1334,7 @@ sub _immutable_metaclass { } return $class_name - if Class::MOP::is_class_loaded($class_name); + if is_class_loaded($class_name); # If the metaclass is a subclass of CMOP::Class which has had # metaclass roles applied (via Moose), then we want to make sure @@ -1423,7 +1424,7 @@ sub _inline_constructor { my $constructor_class = $args{constructor_class}; - Class::MOP::load_class($constructor_class); + load_class($constructor_class); my $constructor = $constructor_class->new( options => \%args, @@ -1460,7 +1461,7 @@ sub _inline_destructor { my $destructor_class = $args{destructor_class}; - Class::MOP::load_class($destructor_class); + load_class($destructor_class); return unless $destructor_class->is_needed($self); diff --git a/lib/Class/MOP/MiniTrait.pm b/lib/Class/MOP/MiniTrait.pm index cb94aad..52c40bc 100644 --- a/lib/Class/MOP/MiniTrait.pm +++ b/lib/Class/MOP/MiniTrait.pm @@ -3,11 +3,13 @@ package Class::MOP::MiniTrait; use strict; use warnings; +use Class::Load qw(load_class); + sub apply { my ( $to_class, $trait ) = @_; for ( grep { !ref } $to_class, $trait ) { - Class::MOP::load_class($_); + load_class($_); $_ = Class::MOP::Class->initialize($_); } diff --git a/lib/Moose.pm b/lib/Moose.pm index f776e12..ecba98c 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -6,6 +6,8 @@ use 5.008; use Scalar::Util 'blessed'; use Carp 'confess'; +use Class::Load 'is_class_loaded'; + use Moose::Deprecated; use Moose::Exporter; @@ -142,7 +144,7 @@ sub init_meta { my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta'; Moose->throw_error("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)") - unless Class::MOP::is_class_loaded($metaclass); + unless is_class_loaded($metaclass); Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Class.") unless $metaclass->isa('Moose::Meta::Class'); diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index fad3c25..3d68743 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -3,6 +3,7 @@ package Moose::Exporter; use strict; use warnings; +use Class::Load qw(is_class_loaded); use Class::MOP; use List::MoreUtils qw( first_index uniq ); use Moose::Util::MetaRole; @@ -144,7 +145,7 @@ sub _make_exporter { my $exporting_package = shift; if ( !exists $EXPORT_SPEC{$exporting_package} ) { - my $loaded = Class::MOP::is_class_loaded($exporting_package); + my $loaded = is_class_loaded($exporting_package); die "Package in also ($exporting_package) does not seem to " . "use Moose::Exporter" diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index b2f1842..65214a3 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -4,8 +4,8 @@ package Moose::Meta::Attribute; use strict; use warnings; -use Class::MOP (); use B (); +use Class::Load qw(is_class_loaded load_class); use Scalar::Util 'blessed', 'weaken'; use List::MoreUtils 'any'; use Try::Tiny; @@ -1147,7 +1147,7 @@ sub _canonicalize_handles { } } - Class::MOP::load_class($handles); + load_class($handles); my $role_meta = Class::MOP::class_of($handles); (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) @@ -1180,7 +1180,7 @@ sub _get_delegate_method_list { sub _find_delegate_metaclass { my $self = shift; if (my $class = $self->_isa_metadata) { - unless ( Class::MOP::is_class_loaded($class) ) { + unless ( is_class_loaded($class) ) { $self->throw_error( sprintf( 'The %s attribute is trying to delegate to a class which has not been loaded - %s', @@ -1194,7 +1194,7 @@ sub _find_delegate_metaclass { return Class::MOP::Class->initialize($class); } elsif (my $role = $self->_does_metadata) { - unless ( Class::MOP::is_class_loaded($class) ) { + unless ( is_class_loaded($class) ) { $self->throw_error( sprintf( 'The %s attribute is trying to delegate to a role which has not been loaded - %s', diff --git a/lib/Moose/Meta/Attribute/Native.pm b/lib/Moose/Meta/Attribute/Native.pm index de10753..cff90f6 100644 --- a/lib/Moose/Meta/Attribute/Native.pm +++ b/lib/Moose/Meta/Attribute/Native.pm @@ -1,5 +1,7 @@ package Moose::Meta::Attribute::Native; +use Class::Load qw(load_class); + my @trait_names = qw(Bool Counter Number String Array Hash Code); for my $trait_name (@trait_names) { @@ -17,7 +19,7 @@ for my $trait_name (@trait_names) { $meta->add_method(register_implementation => sub { # resolve_metatrait_alias will load classes anyway, but throws away # their error message; we WANT to die if there's a problem - Class::MOP::load_class($trait_class); + load_class($trait_class); return $trait_class; }); } diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm index 3728406..b006546 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait.pm @@ -2,6 +2,7 @@ package Moose::Meta::Attribute::Native::Trait; use Moose::Role; +use Class::Load qw(load_class); use List::MoreUtils qw( any uniq ); use Moose::Util::TypeConstraints; use Moose::Deprecated; @@ -176,7 +177,7 @@ sub _native_accessor_class_for { . $self->_native_type . '::' . $suffix; - Class::MOP::load_class($role); + load_class($role); return Moose::Meta::Class->create_anon_class( superclasses => [ $self->accessor_metaclass, $self->delegation_metaclass ], diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index e3883f5..49114ef 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -4,8 +4,8 @@ package Moose::Meta::Class; use strict; use warnings; +use Class::Load qw(load_class); use Class::MOP; - use Carp qw( confess ); use Data::OptList; use List::Util qw( first ); @@ -545,7 +545,7 @@ sub superclasses { my $supers = Data::OptList::mkopt(\@_); foreach my $super (@{ $supers }) { my ($name, $opts) = @{ $super }; - Class::MOP::load_class($name, $opts); + load_class($name, $opts); my $meta = Class::MOP::class_of($name); $self->throw_error("You cannot inherit from a Moose Role ($name)") if $meta && $meta->isa('Moose::Meta::Role') @@ -802,7 +802,7 @@ sub create_error { my $class = ref $self ? $self->error_class : "Moose::Error::Default"; - Class::MOP::load_class($class); + load_class($class); $class->new( Carp::caller_info($args{depth}), @@ -824,7 +824,7 @@ sub _inline_create_error { my $class = ref $self ? $self->error_class : "Moose::Error::Default"; - Class::MOP::load_class($class); + load_class($class); # don't check inheritance here - the intention is that the class needs # to provide a non-inherited inlining method, because falling back to diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index c251b65..4b2d3eb 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -5,6 +5,7 @@ use strict; use warnings; use metaclass; +use Class::Load qw(load_class); use Scalar::Util 'blessed'; use Carp 'confess'; use Devel::GlobalDestruction 'in_global_destruction'; @@ -450,7 +451,7 @@ sub apply { $application_class = $self->application_to_instance_class; } - Class::MOP::load_class($application_class); + load_class($application_class); if ( exists $args{'-excludes'} ) { # I wish we had coercion here :) diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 51e6691..5a38e7a 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -4,6 +4,7 @@ use strict; use warnings; use metaclass; +use Class::Load qw(load_class); use Scalar::Util 'blessed'; use base 'Moose::Meta::Role'; @@ -120,7 +121,7 @@ sub get_method { sub apply_params { my ($self, $role_params) = @_; - Class::MOP::load_class($self->application_role_summation_class); + load_class($self->application_role_summation_class); $self->application_role_summation_class->new( role_params => $role_params, diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index f66888d..2b56617 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -11,6 +11,7 @@ use overload '0+' => sub { refaddr(shift) }, # id an object fallback => 1; use Carp qw(confess); +use Class::Load qw(load_class); use Eval::Closure; use Scalar::Util qw(blessed refaddr); use Sub::Name qw(subname); @@ -56,7 +57,7 @@ my $_default_message_generator = sub { # have to load it late like this, since it uses Moose itself my $can_partialdump = try { # versions prior to 0.14 had a potential infinite loop bug - Class::MOP::load_class('Devel::PartialDump', { -version => 0.14 }); + load_class('Devel::PartialDump', { -version => 0.14 }); 1; }; if ($can_partialdump) { diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index c4ed911..48e40b7 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -4,6 +4,7 @@ use warnings; use Scalar::Util 'blessed'; use Carp 'croak'; +use Class::Load 'is_class_loaded'; use Sub::Exporter; @@ -107,7 +108,7 @@ sub init_meta { my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta'; Moose->throw_error("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)") - unless Class::MOP::is_class_loaded($metaclass); + unless is_class_loaded($metaclass); Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Role.") unless $metaclass->isa('Moose::Meta::Role'); diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 63a4da5..afa6308 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -3,6 +3,7 @@ package Moose::Util; use strict; use warnings; +use Class::Load qw(load_class load_first_existing_class); use Data::OptList; use Params::Util qw( _STRING ); use Sub::Exporter; @@ -122,7 +123,7 @@ sub _apply_all_roles { $meta = $role->[0]; } else { - Class::MOP::load_class( $role->[0] , $role->[1] ); + load_class( $role->[0] , $role->[1] ); $meta = find_meta( $role->[0] ); } @@ -142,7 +143,7 @@ sub _apply_all_roles { return unless @role_metas; - Class::MOP::load_class($applicant) + load_class($applicant) unless blessed($applicant) || Class::MOP::class_of($applicant); @@ -215,7 +216,7 @@ sub _build_alias_package_name { $type, $metaclass_name, $options{trait} ); - my $loaded_class = Class::MOP::load_first_existing_class( + my $loaded_class = load_first_existing_class( $possible_full_name, $metaclass_name ); diff --git a/lib/Moose/Util/TypeConstraints/Builtins.pm b/lib/Moose/Util/TypeConstraints/Builtins.pm index 7fbe021..7ea867c 100644 --- a/lib/Moose/Util/TypeConstraints/Builtins.pm +++ b/lib/Moose/Util/TypeConstraints/Builtins.pm @@ -3,6 +3,7 @@ package Moose::Util::TypeConstraints::Builtins; use strict; use warnings; +use Class::Load qw( is_class_loaded ); use List::MoreUtils (); use Scalar::Util qw( blessed looks_like_number reftype ); @@ -132,9 +133,9 @@ sub define_builtins { subtype 'ClassName' => as 'Str' - => where { Class::MOP::is_class_loaded($_) } + => where { is_class_loaded($_) } # the long Str tests are redundant here - => inline_as { 'Class::MOP::is_class_loaded(' . $_[1] . ')' }; + => inline_as { 'Class::Load::is_class_loaded(' . $_[1] . ')' }; subtype 'RoleName' => as 'ClassName' diff --git a/lib/metaclass.pm b/lib/metaclass.pm index 17e0e97..a41c2fe 100644 --- a/lib/metaclass.pm +++ b/lib/metaclass.pm @@ -5,6 +5,7 @@ use strict; use warnings; use Carp 'confess'; +use Class::Load 'load_class'; use Scalar::Util 'blessed'; use Try::Tiny; @@ -22,7 +23,7 @@ sub import { unless ( defined $metaclass ) { $metaclass = "Class::MOP::Class"; } else { - Class::MOP::load_class($metaclass); + load_class($metaclass); } ($metaclass->isa('Class::MOP::Class')) @@ -31,7 +32,7 @@ sub import { # make sure the custom metaclasses get loaded foreach my $key (grep { /_(?:meta)?class$/ } keys %options) { unless ( ref( my $class = $options{$key} ) ) { - Class::MOP::load_class($class) + load_class($class) } } diff --git a/lib/oose.pm b/lib/oose.pm index 1ee77b8..cd87abc 100644 --- a/lib/oose.pm +++ b/lib/oose.pm @@ -3,7 +3,7 @@ package oose; use strict; use warnings; -use Class::MOP; +use Class::Load qw(load_class); BEGIN { my $package; @@ -11,7 +11,7 @@ BEGIN { $package = $_[1] || 'Class'; if ($package =~ /^\+/) { $package =~ s/^\+//; - Class::MOP::load_class($package); + load_class($package); } } use Filter::Simple sub { s/^/package $package;\nuse Moose;use Moose::Util::TypeConstraints;\n/; } diff --git a/t/cmop/BinaryTree_test.t b/t/cmop/BinaryTree_test.t index f6f1c37..1d97a92 100644 --- a/t/cmop/BinaryTree_test.t +++ b/t/cmop/BinaryTree_test.t @@ -7,7 +7,7 @@ use File::Spec::Functions; use Test::More; use Test::Fatal; -use Class::MOP; +use Class::Load qw( is_class_loaded load_class ); use lib catdir($FindBin::Bin, 'lib'); @@ -15,13 +15,13 @@ use lib catdir($FindBin::Bin, 'lib'); ## These are all tests which are derived from the Tree::Binary test suite ## ---------------------------------------------------------------------------- -ok(!Class::MOP::is_class_loaded('BinaryTree'), '... the binary tree class is not loaded'); +ok(!is_class_loaded('BinaryTree'), '... the binary tree class is not loaded'); is( exception { - Class::MOP::load_class('BinaryTree'); + load_class('BinaryTree'); }, undef, '... loaded the BinaryTree class without dying' ); -ok(Class::MOP::is_class_loaded('BinaryTree'), '... the binary tree class is now loaded'); +ok(is_class_loaded('BinaryTree'), '... the binary tree class is now loaded'); ## ---------------------------------------------------------------------------- ## t/10_Tree_Binary_test.t diff --git a/t/cmop/load.t b/t/cmop/load.t index f6b3ec4..596a35b 100644 --- a/t/cmop/load.t +++ b/t/cmop/load.t @@ -3,6 +3,8 @@ use warnings; use Test::More; +use Class::Load qw(is_class_loaded); + BEGIN { use_ok('Class::MOP'); use_ok('Class::MOP::Mixin'); @@ -49,7 +51,7 @@ my %METAS = ( 'Class::MOP::Class::Immutable::Class::MOP::Class' => Class::MOP::Class::Immutable::Class::MOP::Class->meta, ); -ok( Class::MOP::is_class_loaded($_), '... ' . $_ . ' is loaded' ) +ok( is_class_loaded($_), '... ' . $_ . ' is loaded' ) for keys %METAS; for my $meta (values %METAS) { diff --git a/t/cmop/magic.t b/t/cmop/magic.t index 1969253..cbb9bba 100644 --- a/t/cmop/magic.t +++ b/t/cmop/magic.t @@ -7,6 +7,7 @@ use warnings; use Test::More; use Test::Fatal; +use Class::Load qw( is_class_loaded load_class ); use Class::MOP; use Tie::Scalar; @@ -55,13 +56,13 @@ use Tie::Scalar; { my $x = tie my $value, 'Tie::StdScalar', 'Class::MOP'; - is( exception { Class::MOP::load_class($value) }, undef, 'load_class(tied scalar)' ); + is( exception { load_class($value) }, undef, 'load_class(tied scalar)' ); $value = undef; $x->STORE('Class::MOP'); # reset is( exception { - ok Class::MOP::is_class_loaded($value); + ok is_class_loaded($value); }, undef, 'is_class_loaded(tied scalar)' ); $value = undef; diff --git a/t/cmop/metaclass_loads_classes.t b/t/cmop/metaclass_loads_classes.t index 5ae9069..67dbde8 100644 --- a/t/cmop/metaclass_loads_classes.t +++ b/t/cmop/metaclass_loads_classes.t @@ -6,7 +6,7 @@ use File::Spec::Functions; use Test::More; -use Class::MOP; +use Class::Load qw(is_class_loaded); use lib catdir($FindBin::Bin, 'lib'); @@ -27,15 +27,15 @@ use lib catdir($FindBin::Bin, 'lib'); my $meta = Foo->meta; isa_ok($meta, 'MyMetaClass', '... Correct metaclass'); -ok(Class::MOP::is_class_loaded('MyMetaClass'), '... metaclass loaded'); +ok(is_class_loaded('MyMetaClass'), '... metaclass loaded'); is($meta->attribute_metaclass, 'MyMetaClass::Attribute', '... Correct attribute metaclass'); -ok(Class::MOP::is_class_loaded('MyMetaClass::Attribute'), '... attribute metaclass loaded'); +ok(is_class_loaded('MyMetaClass::Attribute'), '... attribute metaclass loaded'); is($meta->instance_metaclass, 'MyMetaClass::Instance', '... Correct instance metaclass'); -ok(Class::MOP::is_class_loaded('MyMetaClass::Instance'), '... instance metaclass loaded'); +ok(is_class_loaded('MyMetaClass::Instance'), '... instance metaclass loaded'); is($meta->method_metaclass, 'MyMetaClass::Method', '... Correct method metaclass'); -ok(Class::MOP::is_class_loaded('MyMetaClass::Method'), '... method metaclass loaded'); +ok(is_class_loaded('MyMetaClass::Method'), '... method metaclass loaded'); done_testing; diff --git a/t/immutable/inline_close_over.t b/t/immutable/inline_close_over.t index 400261d..107258c 100644 --- a/t/immutable/inline_close_over.t +++ b/t/immutable/inline_close_over.t @@ -3,11 +3,12 @@ use strict; use warnings; use Test::More; +use Class::Load 'load_class'; use Test::Requires 'Data::Visitor'; use Test::Requires 'PadWalker'; use Try::Tiny; my $can_partialdump = try { - Class::MOP::load_class('Devel::PartialDump', { -version => 0.14 }); 1; + load_class('Devel::PartialDump', { -version => 0.14 }); 1; }; { diff --git a/t/roles/anonymous_roles.t b/t/roles/anonymous_roles.t index dc58861..549ab85 100644 --- a/t/roles/anonymous_roles.t +++ b/t/roles/anonymous_roles.t @@ -4,6 +4,8 @@ use warnings; use Test::More; use Moose (); +use Class::Load qw(is_class_loaded); + my $role = Moose::Meta::Role->create_anon_role( attributes => { is_worn => { @@ -30,7 +32,7 @@ ok(!$visored->is_worn, "method was consumed"); like($role->name, qr/^Moose::Meta::Role::__ANON__::SERIAL::\d+$/, ""); ok($role->is_anon_role, "the role knows it's anonymous"); -ok(Class::MOP::is_class_loaded(Moose::Meta::Role->create_anon_role->name), "creating an anonymous role satisifes is_class_loaded"); +ok(is_class_loaded(Moose::Meta::Role->create_anon_role->name), "creating an anonymous role satisifes is_class_loaded"); ok(Class::MOP::class_of(Moose::Meta::Role->create_anon_role->name), "creating an anonymous role satisifes class_of"); done_testing;