Data::ObjectPerl module for providing OO methods to Perl data structures | |
Download |
Data::Object Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Publisher Name:
- Jason Fried
- Publisher web site:
- http://search.cpan.org/~fried/
Data::Object Tags
Data::Object Description
Perl module for providing OO methods to Perl data structures Data::Object is a Perl module that attempts to provide class style accessors for Perl data structures. In an attempt to make it easier to traverse said data structures in an OO way.Currently only Array and Hash structures are handled in any way, all others are returned as is.SYNOPSIS use Data::Object; #Simpsons Data Refrence my $ref = { name => "Homer Simpson", children => , age => 38, job => "Safety Inspector", gender => "Male", wife => { name => "Marge Simpson", age => 36, job => "Housewife", gender => "Female" } }; #Wrap the given refrence and return a class for working with the data. my $homer = Data::Object->wrap($ref); print $homer->wife->name; # "Marge Simpson" print $homer->children->count; # 3 my $marge = $home->wife; $marge->children($homer->children); # Homers kids are now Marges kids $marge->set("children",$home->get("children")); #SAME #Base Data Structure is left in tact, and modified as one would think. print $homer->wife->children->count; # 3 #Traverse easily through an array of hashes print $homer->children->first( sub { $_->name eq "Lisa Simpson" } )->age; # 8 #Get Homers Daughters my @homers_girls = $homer->children->grep( sub { $_->gender eq "Female" } ); foreach (@homers_girls) { print "Name: ",$_->name," Age: ",$_->age,"\n"; } Requirements: · Perl
Data::Object Related Software