[VPM] strange warning I'm getting
Darren Duncan
darren at DarrenDuncan.net
Tue Sep 9 01:25:35 CDT 2003
Hello.
When I'm running a test program which contains the following method, I keep getting a warning on the line containing "if( !$def_parent ) {" which says "Use of uninitialized value in hash element at SQL/ObjectModel.pm line 1573.".
However, that line makes no references to a hash.
Debugging hasn't helped so far, except that the warning is generated when $def_parent has a value and it isn't generated when the variable is null; that variable is a simple string. Also, the only time the null value is in the variable is the first time the method is called.
Also, if I replace !$def_parent with anything else, I still get the same warning. If I put something like "1;" on the following line, I still get it. If I add more lines of various kinds above the "if" line, I still get the Warning on the line.
I have run the program with both Perl 5.6.0 and 5.8.1rc4; they both give me the same Warning, which suggests either it may not be a bug in Perl itself, or I have discovered a new bug.
Also, the test program produces the correct output
So if you have any suggestions on what I am doing wrong, then I would appreciate knowing.
I have refrained from sending the whole module/test-program, since it is about 120K in size.
sub set_parent_node {
my ($self, $parent) = @_;
my $container = $self->{$PROP_CONTAINER};
if( $self->{$PROP_PARENT_NODE} ) {
$self->unlink_parent_node();
}
my $node_type = $self->{$PROP_NODE_TYPE};
if( UNIVERSAL::isa($parent,'SQL::ObjectModel::_::Node') ) {
unless( $parent->{$PROP_CONTAINER} eq $self->{$PROP_CONTAINER} ) {
Carp::confess( "$CLSNM->set_parent_node(): invalid PARENT argument; ".
"that Node is not in the same container as the current Node" );
}
my $p_node_type = $parent->{$PROP_NODE_TYPE};
my $p_type_info = $NODE_TYPES{$p_node_type};
unless( $p_type_info->{'children'}->{$node_type} ) {
Carp::confess( "$CLSNM->set_parent_node(): invalid PARENT argument; ".
"a node of type '$p_node_type' may not have ".
"a child node of type '$node_type'" );
}
} else {
my $type_info = $NODE_TYPES{$node_type};
my $def_parent = $type_info->{'def_parent'};
if( !$def_parent ) {
# do nothing (or throw error)
} elsif( $container->{$PROP_ALL_NODES}->{$def_parent}->{$parent} ) {
# PARENT matches a valid node id that we can link to.
$parent = $container->{$PROP_ALL_NODES}->{$def_parent}->{$parent};
} elsif( $parent ) {
# See if PARENT matches a non-id node attribute we can link to.
# Note that this will only work properly if used attribute value is unique.
my $link_search_attr = $NODE_TYPES{$def_parent}->{'link_search_attr'};
foreach my $scn (values %{$container->{$PROP_ALL_NODES}->{$def_parent}}) {
if( $scn->{$PROP_NODE_ATTRS}->{$link_search_attr} eq $parent ) {
$parent = $scn;
last;
}
}
} else {
$parent = $container->{$PROP_LAST_NODES}->{$def_parent};
}
}
if( $parent ) {
$self->{$PROP_PARENT_NODE} = $parent;
push( @{$parent->{$PROP_CHILD_NODES}}, $self );
}
}
More information about the Victoria-pm
mailing list