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
    Finally I got it: the correct way was: $CFVs->{custom_field}->{values}->{name}; Thanks for your help
      This abuses the internal representation of the object and breaks encapsulation. It can also bypass triggers or similar advanced features.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]