Author: spadkins
Date: Tue Jun 26 08:30:18 2007
New Revision: 9683
Modified:
p5ee/trunk/App-Context/lib/App/Reference.pm
Log:
cleaned up the overlay() method
Modified: p5ee/trunk/App-Context/lib/App/Reference.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Reference.pm (original)
+++ p5ee/trunk/App-Context/lib/App/Reference.pm Tue Jun 26 08:30:18 2007
@@ -327,28 +327,21 @@
sub overlay {
&App::sub_entry if ($App::trace);
- my $self = shift;
- my ($ref1, $ref2, $key);
- return if ($#_ < 0 || $#_ > 1);
- if ($#_ == 0) {
+ my ($self, $ref1, $ref2) = @_;
+ if (!defined $ref2) {
+ $ref2 = $ref1;
$ref1 = $self;
- $ref2 = $_[0];
- }
- else {
- $ref1 = $_[0];
- $ref2 = $_[1];
}
my $ref1type = ref($ref1);
my $ref2type = ref($ref2);
- if ($ref1type eq "ARRAY" && $ref1type eq $ref2type) {
- # array: nothing to do
- }
- elsif ($ref1type eq "" && $ref1type eq $ref2type) {
+ if ($ref1type eq "" || $ref2type eq "") {
# scalar: nothing to do
}
- else {
- # hash
- foreach $key (keys %$ref2) {
+ elsif ($ref1type eq "ARRAY" || $ref2type eq "ARRAY") {
+ # array: nothing to do
+ }
+ else { # assume they are both hashes
+ foreach my $key (keys %$ref2) {
if (!exists $ref1->{$key}) {
$ref1->{$key} = $ref2->{$key};
}
@@ -356,7 +349,7 @@
$ref1type = ref($ref1->{$key});
if ($ref1type && $ref1type ne "ARRAY") {
$ref2type = ref($ref2->{$key});
- if ($ref1type eq $ref2type) {
+ if ($ref2type && $ref2type ne "ARRAY") {
$self->overlay($ref1->{$key}, $ref2->{$key});
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.