use Sub::Name 'subname';
use B 'svref_2object';
-our $VERSION = '0.16';
+our $VERSION = '0.17';
use base 'Class::MOP::Module';
$class = blessed($class) || $class;
# now create the metaclass
my $meta;
- if ($class =~ /^Class::MOP::/) {
+ if ($class =~ /^Class::MOP::Class$/) {
$meta = bless {
'$:package' => $package_name,
'%:attributes' => {},
sub superclasses {
my $self = shift;
- no strict 'refs';
if (@_) {
my @supers = @_;
- @{$self->name . '::ISA'} = @supers;
+ @{$self->get_package_symbol('@ISA')} = @supers;
# NOTE:
# we need to check the metaclass
# compatability here so that we can
# we don't know about
$self->check_metaclass_compatability();
}
- @{$self->name . '::ISA'};
+ @{$self->get_package_symbol('@ISA')};
}
sub class_precedence_list {
|| confess "Your code block must be a CODE reference";
my $full_method_name = ($self->name . '::' . $method_name);
+ # FIXME:
+ # dont bless subs, its bad mkay
$method = $self->method_metaclass->wrap($method) unless blessed($method);
- no strict 'refs';
- no warnings 'redefine';
- *{$full_method_name} = subname $full_method_name => $method;
+ $self->add_package_symbol("&${method_name}" => subname $full_method_name => $method);
}
{
# use reftype here to allow for blessed subs ...
('CODE' eq (reftype($method) || ''))
|| confess "Your code block must be a CODE reference";
- my $full_method_name = ($self->name . '::' . $method_name);
+ # FIXME:
+ # dont bless subs, its bad mkay
$method = $self->method_metaclass->wrap($method) unless blessed($method);
- no strict 'refs';
- no warnings 'redefine';
- *{$full_method_name} = $method;
+ $self->add_package_symbol("&${method_name}" => $method);
}
sub find_method_by_name {
- my ( $self, $method_name ) = @_;
-
- return $self->name->can( $method_name );
+ my ($self, $method_name) = @_;
+ return $self->name->can($method_name);
}
sub has_method {
my ($self, $method_name) = @_;
(defined $method_name && $method_name)
|| confess "You must define a method name";
-
- my $sub_name = ($self->name . '::' . $method_name);
- no strict 'refs';
- return 0 if !defined(&{$sub_name});
- my $method = \&{$sub_name};
+ return 0 if !$self->has_package_symbol("&${method_name}");
+ my $method = $self->get_package_symbol("&${method_name}");
return 0 if (svref_2object($method)->GV->STASH->NAME || '') ne $self->name &&
(svref_2object($method)->GV->NAME || '') ne '__ANON__';
- #if ( $self->name->can("meta") ) {
- # don't bless (destructive operation) classes that didn't ask for it
-
- # at this point we are relatively sure
- # it is our method, so we bless/wrap it
- $self->method_metaclass->wrap($method) unless blessed($method);
- #}
+ # FIXME:
+ # dont bless subs, its bad mkay
+ $self->method_metaclass->wrap($method) unless blessed($method);
+
return 1;
}
|| confess "You must define a method name";
return unless $self->has_method($method_name);
-
- no strict 'refs';
- return \&{$self->name . '::' . $method_name};
+
+ return $self->get_package_symbol("&${method_name}");
}
sub remove_method {
my $removed_method = $self->get_method($method_name);
- no strict 'refs';
- delete ${$self->name . '::'}{$method_name}
+ $self->remove_package_symbol("&${method_name}")
if defined $removed_method;
return $removed_method;
sub get_method_list {
my $self = shift;
- no strict 'refs';
- grep { $self->has_method($_) } keys %{$self->name . '::'};
+ grep { $self->has_method($_) } $self->list_all_package_symbols;
}
sub compute_all_applicable_methods {
$attribute->attach_to_class($self);
$attribute->install_accessors();
$self->get_attribute_map->{$attribute->name} = $attribute;
-
- # FIXME
- # in theory we have to tell everyone the slot structure may have changed
}
sub has_attribute {
use Scalar::Util 'blessed';
use Carp 'confess';
-our $VERSION = '0.01';
+our $VERSION = '0.02';
# introspection
# creation ...
sub initialize {
- my ($class, $package) = @_;
- bless { '$:package' => $package } => $class;
+ my $class = shift;
+ my $package_name = shift;
+ # we hand-construct the class
+ # until we can bootstrap it
+ return bless { '$:package' => $package_name } => $class;
}
# Attributes
|| confess "I do not recognize that sigil '$sigil'";
no strict 'refs';
- no warnings 'misc';
+ no warnings 'misc', 'redefine';
*{$self->name . '::' . $name} = $initial_value;
}
undef %{$self->name . '::' . $name};
}
elsif ($SIGIL_MAP{$sigil} eq 'CODE') {
- undef &{$self->name . '::' . $name};
+ # FIXME:
+ # this is crap, it is probably much
+ # easier to write this in XS.
+ my ($scalar, @array, %hash);
+ $scalar = ${$self->name . '::' . $name} if defined *{$self->name . '::' . $name}{SCALAR};
+ @array = @{$self->name . '::' . $name} if defined *{$self->name . '::' . $name}{ARRAY};
+ %hash = %{$self->name . '::' . $name} if defined *{$self->name . '::' . $name}{HASH};
+ delete ${$self->name . '::'}{$name};
+ ${$self->name . '::' . $name} = $scalar if defined $scalar;
+ @{$self->name . '::' . $name} = @array if scalar @array;
+ %{$self->name . '::' . $name} = %hash if keys %hash;
}
else {
confess "This should never ever ever happen";
}
}
+
+}
+sub list_all_package_symbols {
+ my ($self) = @_;
+ no strict 'refs';
+ return keys %{$self->name . '::'};
}
1;
=item B<remove_package_symbol>
+=item B<list_all_package_symbols>
+
=back
=head1 AUTHORS