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 | |
eca95e04 |
10 | our $VERSION = '0.78'; |
d519662a |
11 | $VERSION = eval $VERSION; |
f0480c45 |
12 | our $AUTHORITY = 'cpan:STEVAN'; |
2243a22b |
13 | |
14 | use base 'Class::MOP::Package'; |
15 | |
7f436b8c |
16 | sub version { |
17 | my $self = shift; |
8b49a472 |
18 | ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'VERSION' })}; |
7f436b8c |
19 | } |
20 | |
f0480c45 |
21 | sub authority { |
22 | my $self = shift; |
8b49a472 |
23 | ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'AUTHORITY' })}; |
f0480c45 |
24 | } |
9d6dce77 |
25 | |
f0480c45 |
26 | sub identifier { |
27 | my $self = shift; |
28 | join '-' => ( |
29 | $self->name, |
30 | ($self->version || ()), |
31 | ($self->authority || ()), |
32 | ); |
33 | } |
9d6dce77 |
34 | |
4edd0667 |
35 | sub create { |
36 | my ( $class, %options ) = @_; |
37 | |
38 | my $package_name = $options{package}; |
39 | |
40 | (defined $package_name && $package_name) |
41 | || confess "You must pass a package name"; |
42 | |
43 | my $code = "package $package_name;"; |
44 | $code .= "\$$package_name\:\:VERSION = '" . $options{version} . "';" |
45 | if exists $options{version}; |
46 | $code .= "\$$package_name\:\:AUTHORITY = '" . $options{authority} . "';" |
47 | if exists $options{authority}; |
48 | |
49 | eval $code; |
50 | confess "creation of $package_name failed : $@" if $@; |
51 | |
52 | return; # XXX: should this return some kind of meta object? ~sartak |
53 | } |
54 | |
2243a22b |
55 | 1; |
56 | |
57 | __END__ |
58 | |
59 | =pod |
60 | |
61 | =head1 NAME |
62 | |
63 | Class::MOP::Module - Module Meta Object |
64 | |
2243a22b |
65 | =head1 DESCRIPTION |
66 | |
3d964063 |
67 | A module is essentially a L<Class::MOP::Package> with metadata, in our |
68 | case the version and authority. |
127d39a7 |
69 | |
121991f6 |
70 | =head1 INHERITANCE |
71 | |
3d964063 |
72 | B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>. |
121991f6 |
73 | |
2243a22b |
74 | =head1 METHODS |
75 | |
76 | =over 4 |
77 | |
3d964063 |
78 | =item B<< $metamodule->version >> |
2243a22b |
79 | |
3d964063 |
80 | This is a read-only attribute which returns the C<$VERSION> of the |
81 | package, if one exists. |
127d39a7 |
82 | |
3d964063 |
83 | =item B<< $metamodule->authority >> |
127d39a7 |
84 | |
3d964063 |
85 | This is a read-only attribute which returns the C<$AUTHORITY> of the |
86 | package, if one exists. |
127d39a7 |
87 | |
3d964063 |
88 | =item B<< $metamodule->identifier >> |
7f436b8c |
89 | |
3d964063 |
90 | This constructs a string which combines the name, version and |
91 | authority. |
b9d9fc0b |
92 | |
d678919e |
93 | =item B<< Class::MOP::Module->meta >> |
f0480c45 |
94 | |
3d964063 |
95 | This will return a L<Class::MOP::Class> instance for this class. |
4edd0667 |
96 | |
2243a22b |
97 | =back |
98 | |
1a09d9cc |
99 | =head1 AUTHORS |
2243a22b |
100 | |
101 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
102 | |
103 | =head1 COPYRIGHT AND LICENSE |
104 | |
070bb6c9 |
105 | Copyright 2006-2009 by Infinity Interactive, Inc. |
2243a22b |
106 | |
107 | L<http://www.iinteractive.com> |
108 | |
109 | This library is free software; you can redistribute it and/or modify |
110 | it under the same terms as Perl itself. |
111 | |
ebce5539 |
112 | =cut |