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