HEX
Server: Apache
System: Linux box5134.bluehost.com 5.14.0-162.23.1.9991722448259.nf.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 31 18:11:45 UTC 2024 x86_64
User: bqfpihmy (1846)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //proc/self/root/usr/share/doc/perl-Hash-FieldHash/example/namedfields.pl
#!perl -w
use strict;

package MyClass;
use Hash::FieldHash qw(:all);

fieldhash my %foo => 'foo';

sub new{
	my $class = shift;
	my $self  = bless {}, $class;
	return from_hash($self, @_);
}

package MyDerivedClass;
use parent -norequire => 'MyClass';
use Hash::FieldHash qw(:all);

fieldhash my %bar => 'bar';

package main;

my $o = MyDerivedClass->new(foo => 10, bar => 20);
my $p = MyDerivedClass->new('MyClass::foo' => 10, 'MyDerivedClass::bar' => 20);

use Data::Dumper;
print Dumper($o->to_hash()); 
# $VAR1 = { foo => 10, bar => 20 }

print Dumper($o->to_hash(-fully_qualify));
# $VAR1 = { 'MyClass::foo' => 10, 'MyDerived::bar' => 20 }