From: Shawn M Moore Date: Tue, 25 Nov 2008 05:14:15 +0000 (+0000) Subject: Move the actual module/package creation from Class::MOP::Class to Class::MOP::Module X-Git-Tag: 0.71~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4edd0667cd0f156b04eda1a630033afb3fbab708;p=gitmo%2FClass-MOP.git Move the actual module/package creation from Class::MOP::Class to Class::MOP::Module --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index a1c7260..0686bd7 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -250,9 +250,6 @@ sub create { my (%options) = @args; my $package_name = $options{package}; - (defined $package_name && $package_name) - || confess "You must pass a package name"; - (ref $options{superclasses} eq 'ARRAY') || confess "You must pass an ARRAY ref of superclasses" if exists $options{superclasses}; @@ -265,14 +262,7 @@ sub create { || confess "You must pass an HASH ref of methods" if exists $options{methods}; - my $code = "package $package_name;"; - $code .= "\$$package_name\:\:VERSION = '" . $options{version} . "';" - if exists $options{version}; - $code .= "\$$package_name\:\:AUTHORITY = '" . $options{authority} . "';" - if exists $options{authority}; - - eval $code; - confess "creation of $package_name failed : $@" if $@; + $class->SUPER::create(%options); my (%initialize_options) = @args; delete @initialize_options{qw( diff --git a/lib/Class/MOP/Module.pm b/lib/Class/MOP/Module.pm index f0dd3d7..b4a2cb4 100644 --- a/lib/Class/MOP/Module.pm +++ b/lib/Class/MOP/Module.pm @@ -4,6 +4,7 @@ package Class::MOP::Module; use strict; use warnings; +use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.70_01'; @@ -31,6 +32,26 @@ sub identifier { ); } +sub create { + my ( $class, %options ) = @_; + + my $package_name = $options{package}; + + (defined $package_name && $package_name) + || confess "You must pass a package name"; + + my $code = "package $package_name;"; + $code .= "\$$package_name\:\:VERSION = '" . $options{version} . "';" + if exists $options{version}; + $code .= "\$$package_name\:\:AUTHORITY = '" . $options{authority} . "';" + if exists $options{authority}; + + eval $code; + confess "creation of $package_name failed : $@" if $@; + + return; # XXX: should this return some kind of meta object? ~sartak +} + 1; __END__ @@ -74,6 +95,10 @@ package for the given instance. This constructs a string of the name, version and authority. +=item B + +This creates the module; it does not return a useful result. + =back =head1 AUTHORS diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 748500d..eb00ac3 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 232; +use Test::More tests => 234; use Test::Exception; use Class::MOP; @@ -42,7 +42,7 @@ my @class_mop_package_methods = qw( my @class_mop_module_methods = qw( _new - version authority identifier + version authority identifier create ); my @class_mop_class_methods = qw(