Docs for CMOP::Object
[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
127d39a7 67This is an abstraction of a Perl 5 module, it is a superclass of
68L<Class::MOP::Class>. A module essentially a package with metadata,
69in our case the version and authority.
70
121991f6 71=head1 INHERITANCE
72
73B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>
74
2243a22b 75=head1 METHODS
76
77=over 4
78
79=item B<meta>
80
127d39a7 81Returns a metaclass for this package.
82
83=item B<initialize ($package_name)>
84
85This will initialize a Class::MOP::Module instance which represents
86the module of C<$package_name>.
87
7f436b8c 88=item B<version>
89
b9d9fc0b 90This is a read-only attribute which returns the C<$VERSION> of the
91package for the given instance.
92
f0480c45 93=item B<authority>
94
b9d9fc0b 95This is a read-only attribute which returns the C<$AUTHORITY> of the
96package for the given instance.
97
f0480c45 98=item B<identifier>
99
96e38ba6 100This constructs a string of the name, version and authority.
b9d9fc0b 101
4edd0667 102=item B<create>
103
104This creates the module; it does not return a useful result.
105
2243a22b 106=back
107
1a09d9cc 108=head1 AUTHORS
2243a22b 109
110Stevan Little E<lt>stevan@iinteractive.comE<gt>
111
112=head1 COPYRIGHT AND LICENSE
113
070bb6c9 114Copyright 2006-2009 by Infinity Interactive, Inc.
2243a22b 115
116L<http://www.iinteractive.com>
117
118This library is free software; you can redistribute it and/or modify
119it under the same terms as Perl itself.
120
ebce5539 121=cut