2 package Class::MOP::Module;
8 use Scalar::Util 'blessed';
10 use base 'Class::MOP::Package';
14 return Class::MOP::Class->initialize($class)->new_object(@_)
15 if $class ne __PACKAGE__;
17 my $params = @_ == 1 ? $_[0] : {@_};
19 # Need to quote package to avoid a problem with PPI mis-parsing this
20 # as a package statement.
22 # from Class::MOP::Package
23 'package' => $params->{package},
34 ${$self->get_or_add_package_symbol('$VERSION')};
39 ${$self->get_or_add_package_symbol('$AUTHORITY')};
46 ($self->version || ()),
47 ($self->authority || ()),
55 unshift @args, 'package' if @args % 2 == 1;
58 my $package = delete $options{package};
59 my $version = delete $options{version};
60 my $authority = delete $options{authority};
62 my $meta = $class->SUPER::create($package => %options);
64 $meta->_instantiate_module($version, $authority);
69 sub _anon_package_prefix { 'Class::MOP::Module::__ANON__::SERIAL::' }
70 sub _anon_cache_key { confess "Modules are not cacheable" }
73 sub _instantiate_module {
74 my($self, $version, $authority) = @_;
75 my $package_name = $self->name;
77 Class::MOP::_is_valid_class_name($package_name)
78 || confess "creation of $package_name failed: invalid package name";
81 scalar %{ $package_name . '::' }; # touch the stash
82 ${ $package_name . '::VERSION' } = $version if defined $version;
83 ${ $package_name . '::AUTHORITY' } = $authority if defined $authority;
90 # ABSTRACT: Module Meta Object
98 Class::MOP::Module - Module Meta Object
102 A module is essentially a L<Class::MOP::Package> with metadata, in our
103 case the version and authority.
107 B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>.
113 =item B<< $metamodule->version >>
115 This is a read-only attribute which returns the C<$VERSION> of the
116 package, if one exists.
118 =item B<< $metamodule->authority >>
120 This is a read-only attribute which returns the C<$AUTHORITY> of the
121 package, if one exists.
123 =item B<< $metamodule->identifier >>
125 This constructs a string which combines the name, version and
128 =item B<< Class::MOP::Module->meta >>
130 This will return a L<Class::MOP::Class> instance for this class.