In a module I have code that looks like this... sub add_widget { my $self = shift; my $new_widget = shift; push ( @{$self->{WIDGETS}}, $new_widget ); }
sub get_widgets { my $self = shift; return $self->{WIDGETS}; } I'm writing a test that is failing at runtime with the following error. Can't call method "attrib" on unblessed reference at ./test.pl line 40. $config = new Widget(); my $i = 0; for ($i=0; $i<3; $i++) { my $w = new Widget(); $w->add_attrib("name", "widget".($i+1)); #add_attribute is tested and working $config->add_widget($w); #this is what I'm testing } foreach my $w ( $config->get_widgets() ) { #attrib is tested and working, but this foreach loop is not known to be valid code yet. print $w->attrib("name"); # <---- This is line 40. print "\n"; } my expected output is... widget1 widget2 widget3 -- Ronald Weidner