From 9b31593dae9c4190ca42a517949cecc7b951a38b Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Thu, 22 Oct 2009 10:20:34 -0500 Subject: [PATCH] return undef for ->get() with invalid property --- lib/WebGUI/Definition.pm | 5 ++++- t/Definition.t | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Definition.pm b/lib/WebGUI/Definition.pm index 117997b34..62fada36e 100644 --- a/lib/WebGUI/Definition.pm +++ b/lib/WebGUI/Definition.pm @@ -166,7 +166,10 @@ sub _gen_get { my $self = shift; if (@_) { my $prop = shift; - return $self->$prop; + if ($self->can($prop)) { + return $self->$prop; + } + return undef; } my @all_properties = $self->getProperties; my %props; diff --git a/t/Definition.t b/t/Definition.t index d12d511eb..10a875997 100644 --- a/t/Definition.t +++ b/t/Definition.t @@ -13,6 +13,8 @@ use warnings; no warnings qw(uninitialized); use Test::More 'no_plan'; #tests => 1; +use Test::Exception; + my $called_getProperties; { package WGT::Class; @@ -97,6 +99,12 @@ is_deeply $object->get, { property1 => 'property 1 value' }, is_deeply $subclass_object->get, { property1 => undef, a_property => ' - BLAH', property2 => 'property 2 value' }, 'get returns hash with correct properties'; +is $object->get('property1'), 'property 1 value', + 'get with parameter returns value from accessor'; + +is $object->get('nonExistantProperty'), undef, + 'get with non-existant parameter returns undef'; + is_deeply $object->getProperty('property1'), { label => 'property1 label', defaultValue => $object }, 'getProperty returns correct hash for object'; is_deeply $subclass_object->getProperty('property2'), { label => 'property2 label', defaultValue => 'dynamic value' },