Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    Data::Overlay 0.54

    Download button

    No screenshots available
    Downloads: 107  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Brad Bowman | More programs
    Perl Artistic License / FREE
    March 20th, 2012, 06:06 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Data::Overlay description

    Merge/overlay data with composable changes

    Data::Overlay is a Perl module that can be used to apply a group of changes (also called an overlay) to a data structure, non-destructively, returning a shallow-ish copy with the changes applied. "Shallow-ish" meaning shallow copies at each level along the path of the deeper changes.

     $result = overlay($original, $overlay);

    The algorithm walks the overlay structure, either taking values from it, or when nothing has changed, retaining the values of the original data structure. This means that the only the overlay fully traversed.

    When the overlay is doesn't use any special Data::Overlay keys (ones starting with "="), then the result will be the merger of the original and the overlay, with the overlay taking precedence. In particular, only hashes will really be merged, somewhat like %new = (Þfaults, %options), but recursively. This means that array refs, scalars, code, etc. will be replace whatever is in the original, regardless of the original type (so an array in the overlay will take precedence over an array, hash or scalar in the original). That's why it's not called Data::Underlay.

    Any different merging behaviour needs to be marked with special keys in the overlay called "actions". These start with an "=" sign. (Double it in the overlay to have an actual leading "=" in the result). The actions are described below, but they combine the original and overlay in various ways, pushing/unshifting arrays, only overwriting false or undefined, up to providing ability to write your own combining callback.

    SYNOPSIS

    #!perl -s #line 31

     use strict; use warnings;
     use Data::Overlay qw(overlay compose);
     use Data::Dumper;
     $Data::Dumper::Sortkeys = 1;

     my $data_structure = {
     a => 123,
     b => {
     w => [ "some", "content" ],
     x => "hello",
     y => \"world",
     },
     c => [ 4, 5, 6],
     d => { da => [], db => undef, dc => qr/abc/ },
     };

     my %changes = (
     f => 0, # add top level key
     a => '1, 2, 3', # overwrite key
     b => { z => '!' }, # nested operation
     c => { '=unshift' => 3.5 },# prepend array
     c => { '=push' => 7 }, # append array
     d => { da => [ "DA" ], # replace w/ differing type
     db => {
     '=defor' => 123, # only update if undef
     },
     },
     );

     # apply %changes to $data_structure (read-only ok),
     # returning a new data structure sharing unchanged data with the old
     my $new_data_structure = overlay($data_structure, \%changes);

     # Note sharing shown by Dumper
     print Dumper($data_structure, \%changes, $new_data_structure);



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    overlay data | Perl module | merge data | Perl | merge | overlay

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM