Commit | Line | Data |
2243a22b |
1 | |
2 | package Class::MOP::Module; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
4edd0667 |
7 | use Carp 'confess'; |
2243a22b |
8 | use Scalar::Util 'blessed'; |
9 | |
074ec38f |
10 | our $VERSION = '0.89'; |
d519662a |
11 | $VERSION = eval $VERSION; |
f0480c45 |
12 | our $AUTHORITY = 'cpan:STEVAN'; |
2243a22b |
13 | |
14 | use base 'Class::MOP::Package'; |
15 | |
812d58f9 |
16 | sub _new { |
ec9e38e5 |
17 | my $class = shift; |
18 | return Class::MOP::Class->initialize($class)->new_object(@_) |
812d58f9 |
19 | if $class ne __PACKAGE__; |
ec9e38e5 |
20 | |
21 | my $params = @_ == 1 ? $_[0] : {@_}; |
22 | return bless { |
812d58f9 |
23 | |
ec9e38e5 |
24 | # from Class::MOP::Package |
25 | package => $params->{package}, |
26 | namespace => \undef, |
27 | |
28 | # attributes |
29 | version => \undef, |
30 | authority => \undef |
31 | } => $class; |
32 | } |
33 | |
7f436b8c |
34 | sub version { |
35 | my $self = shift; |
8b49a472 |
36 | ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'VERSION' })}; |
7f436b8c |
37 | } |
38 | |
f0480c45 |
39 | sub authority { |
40 | my $self = shift; |
8b49a472 |
41 | ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'AUTHORITY' })}; |
f0480c45 |
42 | } |
9d6dce77 |
43 | |
f0480c45 |
44 | sub identifier { |
45 | my $self = shift; |
46 | join '-' => ( |
47 | $self->name, |
48 | ($self->version || ()), |
49 | ($self->authority || ()), |
50 | ); |
51 | } |
9d6dce77 |
52 | |
4edd0667 |
53 | sub create { |
89f66023 |
54 | confess "The Class::MOP::Module->create method has been made a private object method.\n"; |
55 | } |
4edd0667 |
56 | |
89f66023 |
57 | sub _instantiate_module { |
dc9c4fde |
58 | my($self, $version, $authority) = @_; |
89f66023 |
59 | my $package_name = $self->name; |
4edd0667 |
60 | |
dc9c4fde |
61 | Class::MOP::_is_valid_class_name($package_name) |
62 | || confess "creation of $package_name failed: invalid package name"; |
89f66023 |
63 | |
dc9c4fde |
64 | no strict 'refs'; |
6f827626 |
65 | scalar %{ $package_name . '::' }; # touch the stash |
66 | ${ $package_name . '::VERSION' } = $version if defined $version; |
67 | ${ $package_name . '::AUTHORITY' } = $authority if defined $authority; |
4edd0667 |
68 | |
dc9c4fde |
69 | return; |
4edd0667 |
70 | } |
71 | |
2243a22b |
72 | 1; |
73 | |
74 | __END__ |
75 | |
76 | =pod |
77 | |
78 | =head1 NAME |
79 | |
80 | Class::MOP::Module - Module Meta Object |
81 | |
2243a22b |
82 | =head1 DESCRIPTION |
83 | |
1f44239e |
84 | A module is essentially a L<Class::MOP::Package> with metadata, in our |
85 | case the version and authority. |
127d39a7 |
86 | |
121991f6 |
87 | =head1 INHERITANCE |
88 | |
1f44239e |
89 | B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>. |
121991f6 |
90 | |
2243a22b |
91 | =head1 METHODS |
92 | |
93 | =over 4 |
94 | |
1f44239e |
95 | =item B<< $metamodule->version >> |
2243a22b |
96 | |
1f44239e |
97 | This is a read-only attribute which returns the C<$VERSION> of the |
98 | package, if one exists. |
127d39a7 |
99 | |
1f44239e |
100 | =item B<< $metamodule->authority >> |
127d39a7 |
101 | |
1f44239e |
102 | This is a read-only attribute which returns the C<$AUTHORITY> of the |
103 | package, if one exists. |
127d39a7 |
104 | |
1f44239e |
105 | =item B<< $metamodule->identifier >> |
7f436b8c |
106 | |
1f44239e |
107 | This constructs a string which combines the name, version and |
108 | authority. |
b9d9fc0b |
109 | |
929e9565 |
110 | =item B<< Class::MOP::Module->meta >> |
f0480c45 |
111 | |
1f44239e |
112 | This will return a L<Class::MOP::Class> instance for this class. |
4edd0667 |
113 | |
2243a22b |
114 | =back |
115 | |
1a09d9cc |
116 | =head1 AUTHORS |
2243a22b |
117 | |
118 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
119 | |
120 | =head1 COPYRIGHT AND LICENSE |
121 | |
070bb6c9 |
122 | Copyright 2006-2009 by Infinity Interactive, Inc. |
2243a22b |
123 | |
124 | L<http://www.iinteractive.com> |
125 | |
126 | This library is free software; you can redistribute it and/or modify |
127 | it under the same terms as Perl itself. |
128 | |
ebce5539 |
129 | =cut |