fix url in POD for meta-model
[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
19042e4d 10our $VERSION = '0.92';
d519662a 11$VERSION = eval $VERSION;
f0480c45 12our $AUTHORITY = 'cpan:STEVAN';
2243a22b 13
14use base 'Class::MOP::Package';
15
812d58f9 16sub _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 34sub version {
35 my $self = shift;
9742ab2a 36 ${$self->get_package_symbol('$VERSION', create => 1)};
7f436b8c 37}
38
f0480c45 39sub authority {
40 my $self = shift;
9742ab2a 41 ${$self->get_package_symbol('$AUTHORITY', create => 1)};
f0480c45 42}
9d6dce77 43
f0480c45 44sub identifier {
45 my $self = shift;
46 join '-' => (
47 $self->name,
48 ($self->version || ()),
49 ($self->authority || ()),
50 );
51}
9d6dce77 52
4edd0667 53sub create {
89f66023 54 confess "The Class::MOP::Module->create method has been made a private object method.\n";
55}
4edd0667 56
89f66023 57sub _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
d6d83287 64 ${ $self->get_package_symbol('$VERSION', create => 1) } = $version;
65 ${ $self->get_package_symbol('$AUTHORITY', create => 1) } = $authority;
4edd0667 66
dc9c4fde 67 return;
4edd0667 68}
69
2243a22b 701;
71
72__END__
73
74=pod
75
76=head1 NAME
77
78Class::MOP::Module - Module Meta Object
79
2243a22b 80=head1 DESCRIPTION
81
1f44239e 82A module is essentially a L<Class::MOP::Package> with metadata, in our
83case the version and authority.
127d39a7 84
121991f6 85=head1 INHERITANCE
86
1f44239e 87B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>.
121991f6 88
2243a22b 89=head1 METHODS
90
91=over 4
92
1f44239e 93=item B<< $metamodule->version >>
2243a22b 94
1f44239e 95This is a read-only attribute which returns the C<$VERSION> of the
96package, if one exists.
127d39a7 97
1f44239e 98=item B<< $metamodule->authority >>
127d39a7 99
1f44239e 100This is a read-only attribute which returns the C<$AUTHORITY> of the
101package, if one exists.
127d39a7 102
1f44239e 103=item B<< $metamodule->identifier >>
7f436b8c 104
1f44239e 105This constructs a string which combines the name, version and
106authority.
b9d9fc0b 107
929e9565 108=item B<< Class::MOP::Module->meta >>
f0480c45 109
1f44239e 110This will return a L<Class::MOP::Class> instance for this class.
4edd0667 111
2243a22b 112=back
113
1a09d9cc 114=head1 AUTHORS
2243a22b 115
116Stevan Little E<lt>stevan@iinteractive.comE<gt>
117
118=head1 COPYRIGHT AND LICENSE
119
070bb6c9 120Copyright 2006-2009 by Infinity Interactive, Inc.
2243a22b 121
122L<http://www.iinteractive.com>
123
124This library is free software; you can redistribute it and/or modify
125it under the same terms as Perl itself.
126
ebce5539 127=cut