Commit | Line | Data |
38bf2a25 |
1 | |
2 | package Class::MOP::Module; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
7 | use Carp 'confess'; |
8 | use Scalar::Util 'blessed'; |
9 | |
38bf2a25 |
10 | use base 'Class::MOP::Package'; |
11 | |
12 | sub _new { |
13 | my $class = shift; |
14 | return Class::MOP::Class->initialize($class)->new_object(@_) |
15 | if $class ne __PACKAGE__; |
16 | |
17 | my $params = @_ == 1 ? $_[0] : {@_}; |
18 | return bless { |
9c1bf11e |
19 | # Need to quote package to avoid a problem with PPI mis-parsing this |
20 | # as a package statement. |
38bf2a25 |
21 | |
22 | # from Class::MOP::Package |
9c1bf11e |
23 | 'package' => $params->{package}, |
38bf2a25 |
24 | namespace => \undef, |
25 | |
26 | # attributes |
27 | version => \undef, |
28 | authority => \undef |
29 | } => $class; |
30 | } |
31 | |
32 | sub version { |
33 | my $self = shift; |
34 | ${$self->get_or_add_package_symbol('$VERSION')}; |
35 | } |
36 | |
37 | sub authority { |
38 | my $self = shift; |
39 | ${$self->get_or_add_package_symbol('$AUTHORITY')}; |
40 | } |
41 | |
42 | sub identifier { |
43 | my $self = shift; |
44 | join '-' => ( |
45 | $self->name, |
46 | ($self->version || ()), |
47 | ($self->authority || ()), |
48 | ); |
49 | } |
50 | |
51 | sub create { |
52 | confess "The Class::MOP::Module->create method has been made a private object method.\n"; |
53 | } |
54 | |
55 | sub _instantiate_module { |
56 | my($self, $version, $authority) = @_; |
57 | my $package_name = $self->name; |
58 | |
59 | Class::MOP::_is_valid_class_name($package_name) |
60 | || confess "creation of $package_name failed: invalid package name"; |
61 | |
62 | no strict 'refs'; |
63 | scalar %{ $package_name . '::' }; # touch the stash |
64 | ${ $package_name . '::VERSION' } = $version if defined $version; |
65 | ${ $package_name . '::AUTHORITY' } = $authority if defined $authority; |
66 | |
67 | return; |
68 | } |
69 | |
70 | 1; |
71 | |
72 | # ABSTRACT: Module Meta Object |
73 | |
74 | __END__ |
75 | |
76 | =pod |
77 | |
78 | =head1 NAME |
79 | |
80 | Class::MOP::Module - Module Meta Object |
81 | |
82 | =head1 DESCRIPTION |
83 | |
84 | A module is essentially a L<Class::MOP::Package> with metadata, in our |
85 | case the version and authority. |
86 | |
87 | =head1 INHERITANCE |
88 | |
89 | B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>. |
90 | |
91 | =head1 METHODS |
92 | |
93 | =over 4 |
94 | |
95 | =item B<< $metamodule->version >> |
96 | |
97 | This is a read-only attribute which returns the C<$VERSION> of the |
98 | package, if one exists. |
99 | |
100 | =item B<< $metamodule->authority >> |
101 | |
102 | This is a read-only attribute which returns the C<$AUTHORITY> of the |
103 | package, if one exists. |
104 | |
105 | =item B<< $metamodule->identifier >> |
106 | |
107 | This constructs a string which combines the name, version and |
108 | authority. |
109 | |
110 | =item B<< Class::MOP::Module->meta >> |
111 | |
112 | This will return a L<Class::MOP::Class> instance for this class. |
113 | |
114 | =back |
115 | |
116 | =cut |