Remove unnecessary calls of has_method()
[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
074ec38f 10our $VERSION = '0.89';
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;
8b49a472 36 ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'VERSION' })};
7f436b8c 37}
38
f0480c45 39sub authority {
40 my $self = shift;
8b49a472 41 ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'AUTHORITY' })};
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
dc9c4fde 64 no strict 'refs';
6f827626 65 scalar %{ $package_name . '::' }; # touch the stash
66 ${ $package_name . '::VERSION' } = $version if defined $version;
67 ${ $package_name . '::AUTHORITY' } = $authority if defined $authority;
4edd0667 68
dc9c4fde 69 return;
4edd0667 70}
71
2243a22b 721;
73
74__END__
75
76=pod
77
78=head1 NAME
79
80Class::MOP::Module - Module Meta Object
81
2243a22b 82=head1 DESCRIPTION
83
1f44239e 84A module is essentially a L<Class::MOP::Package> with metadata, in our
85case the version and authority.
127d39a7 86
121991f6 87=head1 INHERITANCE
88
1f44239e 89B<Class::MOP::Module> is a subclass of L<Class::MOP::Package>.
121991f6 90
2243a22b 91=head1 METHODS
92
93=over 4
94
1f44239e 95=item B<< $metamodule->version >>
2243a22b 96
1f44239e 97This is a read-only attribute which returns the C<$VERSION> of the
98package, if one exists.
127d39a7 99
1f44239e 100=item B<< $metamodule->authority >>
127d39a7 101
1f44239e 102This is a read-only attribute which returns the C<$AUTHORITY> of the
103package, if one exists.
127d39a7 104
1f44239e 105=item B<< $metamodule->identifier >>
7f436b8c 106
1f44239e 107This constructs a string which combines the name, version and
108authority.
b9d9fc0b 109
929e9565 110=item B<< Class::MOP::Module->meta >>
f0480c45 111
1f44239e 112This will return a L<Class::MOP::Class> instance for this class.
4edd0667 113
2243a22b 114=back
115
1a09d9cc 116=head1 AUTHORS
2243a22b 117
118Stevan Little E<lt>stevan@iinteractive.comE<gt>
119
120=head1 COPYRIGHT AND LICENSE
121
070bb6c9 122Copyright 2006-2009 by Infinity Interactive, Inc.
2243a22b 123
124L<http://www.iinteractive.com>
125
126This library is free software; you can redistribute it and/or modify
127it under the same terms as Perl itself.
128
ebce5539 129=cut