# Inheritance
sub superclasses {
- my $self = shift;
+ my $self = shift;
+ my $var_spec = { sigil => '@', type => 'ARRAY', name => 'ISA' };
if (@_) {
my @supers = @_;
- @{$self->get_package_symbol('@ISA')} = @supers;
+ @{$self->get_package_symbol($var_spec)} = @supers;
# NOTE:
# we need to check the metaclass
# compatibility here so that we can
# we don't know about
$self->check_metaclass_compatability();
}
- @{$self->get_package_symbol('@ISA')};
+ @{$self->get_package_symbol($var_spec)};
}
sub subclasses {
$self->get_method_map->{$method_name} = $method;
my $full_method_name = ($self->name . '::' . $method_name);
- $self->add_package_symbol("&${method_name}" =>
+ $self->add_package_symbol(
+ { sigil => '&', type => 'CODE', name => $method_name },
Class::MOP::subname($full_method_name => $body)
);
$self->update_package_cache_flag;
('CODE' eq ref($body))
|| confess "Your code block must be a CODE reference";
- $self->add_package_symbol("&${method_name}" => $body);
+ $self->add_package_symbol(
+ { sigil => '&', type => 'CODE', name => $method_name } => $body
+ );
$self->update_package_cache_flag;
}
my $removed_method = delete $self->get_method_map->{$method_name};
- $self->remove_package_symbol("&${method_name}");
+ $self->remove_package_symbol(
+ { sigil => '&', type => 'CODE', name => $method_name }
+ );
$self->update_package_cache_flag;
sub add_package_symbol {
my ($self, $variable, $initial_value) = @_;
- my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
+ my ($name, $sigil, $type) = ref $variable eq 'HASH'
+ ? @{$variable}{qw[name sigil type]}
+ : $self->_deconstruct_variable_name($variable);
my $pkg = $self->{'$!package'};
sub has_package_symbol {
my ($self, $variable) = @_;
- my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
+ my ($name, $sigil, $type) = ref $variable eq 'HASH'
+ ? @{$variable}{qw[name sigil type]}
+ : $self->_deconstruct_variable_name($variable);
my $namespace = $self->namespace;
sub get_package_symbol {
my ($self, $variable) = @_;
- my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
+ my ($name, $sigil, $type) = ref $variable eq 'HASH'
+ ? @{$variable}{qw[name sigil type]}
+ : $self->_deconstruct_variable_name($variable);
my $namespace = $self->namespace;
sub remove_package_symbol {
my ($self, $variable) = @_;
- my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
+ my ($name, $sigil, $type) = ref $variable eq 'HASH'
+ ? @{$variable}{qw[name sigil type]}
+ : $self->_deconstruct_variable_name($variable);
# FIXME:
# no doubt this is grossly inefficient and
# could be done much easier and faster in XS
+ my ($scalar_desc, $array_desc, $hash_desc, $code_desc) = (
+ { sigil => '$', type => 'SCALAR', name => $name },
+ { sigil => '@', type => 'ARRAY', name => $name },
+ { sigil => '%', type => 'HASH', name => $name },
+ { sigil => '&', type => 'CODE', name => $name },
+ );
+
my ($scalar, $array, $hash, $code);
if ($type eq 'SCALAR') {
- $array = $self->get_package_symbol('@' . $name) if $self->has_package_symbol('@' . $name);
- $hash = $self->get_package_symbol('%' . $name) if $self->has_package_symbol('%' . $name);
- $code = $self->get_package_symbol('&' . $name) if $self->has_package_symbol('&' . $name);
+ $array = $self->get_package_symbol($array_desc) if $self->has_package_symbol($array_desc);
+ $hash = $self->get_package_symbol($hash_desc) if $self->has_package_symbol($hash_desc);
+ $code = $self->get_package_symbol($code_desc) if $self->has_package_symbol($code_desc);
}
elsif ($type eq 'ARRAY') {
- $scalar = $self->get_package_symbol('$' . $name) if $self->has_package_symbol('$' . $name);
- $hash = $self->get_package_symbol('%' . $name) if $self->has_package_symbol('%' . $name);
- $code = $self->get_package_symbol('&' . $name) if $self->has_package_symbol('&' . $name);
+ $scalar = $self->get_package_symbol($scalar_desc) if $self->has_package_symbol($scalar_desc);
+ $hash = $self->get_package_symbol($hash_desc) if $self->has_package_symbol($hash_desc);
+ $code = $self->get_package_symbol($code_desc) if $self->has_package_symbol($code_desc);
}
elsif ($type eq 'HASH') {
- $scalar = $self->get_package_symbol('$' . $name) if $self->has_package_symbol('$' . $name);
- $array = $self->get_package_symbol('@' . $name) if $self->has_package_symbol('@' . $name);
- $code = $self->get_package_symbol('&' . $name) if $self->has_package_symbol('&' . $name);
+ $scalar = $self->get_package_symbol($scalar_desc) if $self->has_package_symbol($scalar_desc);
+ $array = $self->get_package_symbol($array_desc) if $self->has_package_symbol($array_desc);
+ $code = $self->get_package_symbol($code_desc) if $self->has_package_symbol($code_desc);
}
elsif ($type eq 'CODE') {
- $scalar = $self->get_package_symbol('$' . $name) if $self->has_package_symbol('$' . $name);
- $array = $self->get_package_symbol('@' . $name) if $self->has_package_symbol('@' . $name);
- $hash = $self->get_package_symbol('%' . $name) if $self->has_package_symbol('%' . $name);
+ $scalar = $self->get_package_symbol($scalar_desc) if $self->has_package_symbol($scalar_desc);
+ $array = $self->get_package_symbol($array_desc) if $self->has_package_symbol($array_desc);
+ $hash = $self->get_package_symbol($hash_desc) if $self->has_package_symbol($hash_desc);
}
else {
confess "This should never ever ever happen";
$self->remove_package_glob($name);
- $self->add_package_symbol(('$' . $name) => $scalar) if defined $scalar;
- $self->add_package_symbol(('@' . $name) => $array) if defined $array;
- $self->add_package_symbol(('%' . $name) => $hash) if defined $hash;
- $self->add_package_symbol(('&' . $name) => $code) if defined $code;
+ $self->add_package_symbol($scalar_desc => $scalar) if defined $scalar;
+ $self->add_package_symbol($array_desc => $array) if defined $array;
+ $self->add_package_symbol($hash_desc => $hash) if defined $hash;
+ $self->add_package_symbol($code_desc => $code) if defined $code;
}
sub list_all_package_symbols {