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