in reply to Get value from object
Just to see if this could be done :)
NOTE: I faked the rest of your object since yours was incomplete :(
#!/usr/bin/perl -l # https://perlmonks.org/?node_id=1229668 use strict; use warnings; my $CustomField = bless { foo => 1, values => bless({ maxvalues => 1, name => 'Case type', }, 'ClassOne'), bar => 2, }, 'ClassTwo'; use Data::Dumper; print Dumper $CustomField; print '$CustomField->Values->Name = ', $CustomField->Values->Name; ######################## just add this ( hehehe :) sub UNIVERSAL::AUTOLOAD { my $basename = (split /::/, $UNIVERSAL::AUTOLOAD)[-1]; $basename eq 'DESTROY' and return; my ($realname) = grep lc $basename eq lc, keys %{ $_[0] }; defined $realname or die "Missing the key '$basename'"; return $_[0]{$realname}; }
Outputs:
$VAR1 = bless( { 'values' => bless( { 'name' => 'Case type', 'maxvalues' => 1 }, 'ClassOne' ), 'bar' => 2, 'foo' => 1 }, 'ClassTwo' ); $CustomField->Values->Name = Case type
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get value from object
by danny20085 (Initiate) on Feb 11, 2019 at 19:08 UTC | |
by choroba (Cardinal) on Feb 11, 2019 at 19:35 UTC |