docs for CMOP::Module
[gitmo/Class-MOP.git] / lib / Class / MOP / Module.pm
CommitLineData
2243a22b 1
2package Class::MOP::Module;
3
4use strict;
5use warnings;
6
4edd0667 7use Carp 'confess';
2243a22b 8use Scalar::Util 'blessed';
9
eca95e04 10our $VERSION = '0.78';
d519662a 11$VERSION = eval $VERSION;
f0480c45 12our $AUTHORITY = 'cpan:STEVAN';
2243a22b 13
14use base 'Class::MOP::Package';
15
7f436b8c 16sub version {
17 my $self = shift;
8b49a472 18 ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'VERSION' })};
7f436b8c 19}
20
f0480c45 21sub authority {
22 my $self = shift;
8b49a472 23 ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'AUTHORITY' })};
f0480c45 24}
9d6dce77 25
f0480c45 26sub identifier {
27 my $self = shift;
28 join '-' => (
29 $self->name,
30 ($self->version || ()),
31 ($self->authority || ()),
32 );
33}
9d6dce77 34
4edd0667 35sub 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 551;
56
57__END__
58
59=pod
60
61=head1 NAME
62
63Class::MOP::Module - Module Meta Object
64
2243a22b 65=head1 DESCRIPTION
66
d0a47b7d 67A module is essentially a L<Class::MOP::Package> with metadata, in our
68case the version and authority.
127d39a7 69
121991f6 70=head1 INHERITANCE
71
d0a47b7d 72B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>.
121991f6 73
2243a22b 74=head1 METHODS
75
76=over 4
77
d0a47b7d 78=item B<< $metamodule->version >>
2243a22b 79
d0a47b7d 80This is a read-only attribute which returns the C<$VERSION> of the
81package, if one exists.
127d39a7 82
d0a47b7d 83=item B<< $metamodule->authority >>
127d39a7 84
d0a47b7d 85This is a read-only attribute which returns the C<$AUTHORITY> of the
86package, if one exists.
127d39a7 87
d0a47b7d 88=item B<< $metamodule->identifier >>
7f436b8c 89
d0a47b7d 90This constructs a string which combines the name, version and
91authority.
b9d9fc0b 92
d0a47b7d 93=item B<< Class::MOP::Module->meta >
f0480c45 94
d0a47b7d 95This will return a L<Class::MOP::Class> instance for this class.
4edd0667 96
2243a22b 97=back
98
1a09d9cc 99=head1 AUTHORS
2243a22b 100
101Stevan Little E<lt>stevan@iinteractive.comE<gt>
102
103=head1 COPYRIGHT AND LICENSE
104
070bb6c9 105Copyright 2006-2009 by Infinity Interactive, Inc.
2243a22b 106
107L<http://www.iinteractive.com>
108
109This library is free software; you can redistribute it and/or modify
110it under the same terms as Perl itself.
111
ebce5539 112=cut