2 package Class::MOP::Class;
8 use Scalar::Util 'blessed', 'reftype';
9 use Sub::Name 'subname';
10 use B 'svref_2object';
12 our $VERSION = '0.01';
17 my ($class, $package_name) = @_;
18 (defined $package_name)
19 || confess "You must pass a package name";
20 bless \$package_name => $class;
24 my ($class, $package_name, $package_version, %options) = @_;
25 (defined $package_name)
26 || confess "You must pass a package name";
27 my $code = "package $package_name;";
28 $code .= "\$$package_name\:\:VERSION = '$package_version';"
29 if defined $package_version;
31 confess "creation of $package_name failed : $@" if $@;
32 my $meta = $package_name->meta;
33 $meta->superclasses(@{$options{superclasses}})
34 if exists $options{superclasses};
35 # ... rest to come later ...
46 ${$self->name . '::VERSION'};
56 @{$self->name . '::ISA'} = @supers;
58 @{$self->name . '::ISA'};
61 sub class_precedence_list {
66 $_->meta->class_precedence_list()
67 } $self->superclasses()
74 my ($self, $method_name, $method) = @_;
75 (defined $method_name && $method_name)
76 || confess "You must define a method name";
77 (reftype($method) && reftype($method) eq 'CODE')
78 || confess "Your code block must be a CODE reference";
79 my $full_method_name = ($self->name . '::' . $method_name);
82 *{$full_method_name} = subname $full_method_name => $method;
86 my ($self, $method_name, $method) = @_;
87 (defined $method_name && $method_name)
88 || confess "You must define a method name";
90 my $sub_name = ($self->name . '::' . $method_name);
93 return 0 unless defined &{$sub_name};
94 return 0 unless _find_subroutine_package(\&{$sub_name}) eq $self->name;
99 my ($self, $method_name, $method) = @_;
100 (defined $method_name && $method_name)
101 || confess "You must define a method name";
104 return \&{$self->name . '::' . $method_name}
105 if $self->has_method($method_name);
108 ## Private Utility Methods
110 # initially borrowed from Class::Trait 0.20 - Thanks Ovid :)
111 # later re-worked to support subs named with Sub::Name
112 sub _find_subroutine_package {
114 my $package = eval { svref_2object($sub)->GV->STASH->NAME };
115 confess "Could not determine calling package: $@" if $@;
127 Class::MOP::Class - Class Meta Object
135 Stevan Little E<gt>stevan@iinteractive.comE<lt>
137 =head1 COPYRIGHT AND LICENSE
139 Copyright 2006 by Infinity Interactive, Inc.
141 L<http://www.iinteractive.com>
143 This library is free software; you can redistribute it and/or modify
144 it under the same terms as Perl itself.