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