Teach the Perl Fieldmapper.pm to build objects from a hashref in a
similar manner to how the JS Fieldmapper already can.
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
return \%hash;
}
+# To complement to_bare_hash, and to mimic the fromHash method of the
+# JavaScript Fieldmapper, from_bare_hash takes a hashref argument and
+# builds an object from that.
+sub from_bare_hash {
+ my $self = shift;
+ my $hash = shift;
+
+ my $value = $self->new();
+ for my $f ($self->properties) {
+ $value->$f($$hash{$f});
+ }
+
+ return $value;
+}
+
sub clone {
my $self = shift;
return $self->new( [@$self] );