bump version to 0.87
[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.87';
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     confess "The Class::MOP::Module->create method has been made a private object method.\n";
37 }
38
39 sub _instantiate_module {
40     my $self      = shift;
41     my $version   = shift;
42     my $authority = shift;
43
44     my $package_name = $self->name;
45
46     my $code = "package $package_name;";
47
48     $code .= "\$$package_name\:\:VERSION = '" . $version . "';"
49         if defined $version;
50     $code .= "\$$package_name\:\:AUTHORITY = '" . $authority . "';"
51         if defined $authority;
52
53     my $e = do {
54         local $@;
55         local $SIG{__DIE__};
56         eval $code;
57         $@;
58     };
59     confess "creation of $package_name failed : $e" if $e;
60 }
61
62 1;
63
64 __END__
65
66 =pod
67
68 =head1 NAME 
69
70 Class::MOP::Module - Module Meta Object
71
72 =head1 DESCRIPTION
73
74 A module is essentially a L<Class::MOP::Package> with metadata, in our
75 case the version and authority.
76
77 =head1 INHERITANCE
78
79 B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>.
80
81 =head1 METHODS
82
83 =over 4
84
85 =item B<< $metamodule->version >>
86
87 This is a read-only attribute which returns the C<$VERSION> of the
88 package, if one exists.
89
90 =item B<< $metamodule->authority >>
91
92 This is a read-only attribute which returns the C<$AUTHORITY> of the
93 package, if one exists.
94
95 =item B<< $metamodule->identifier >>
96
97 This constructs a string which combines the name, version and
98 authority.
99
100 =item B<< Class::MOP::Module->meta >>
101
102 This will return a L<Class::MOP::Class> instance for this class.
103
104 =back
105
106 =head1 AUTHORS
107
108 Stevan Little E<lt>stevan@iinteractive.comE<gt>
109
110 =head1 COPYRIGHT AND LICENSE
111
112 Copyright 2006-2009 by Infinity Interactive, Inc.
113
114 L<http://www.iinteractive.com>
115
116 This library is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself.
118
119 =cut