-
-
22 Nov 2021 22:52:12 UTC
- Distribution: RapidApp
- Module version: 0.08
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (69 / 0 / 1)
- Kwalitee
Bus factor: 2- % Coverage
- License: perl_5
- Perl: v5.10.0
- Activity
24 month- Tools
- Download (2.29MB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 14 contributors-
Michael Conrad
-
Torsten Raudssus
-
Peter Rabbitson
-
Deven T. Corzine
-
Roy Tate
-
Nicholas Foos
-
Michael Lackhoff
-
Tom Bloor
-
Matt S. Trout
-
Scott Walters
-
Tim Bunce
-
Dagfinn Ilmari Mannsåker
-
Roman Pavlov
-
James Wright
- Dependencies
- Alien::Web::ExtJS::V3
- Attribute::Handlers
- B::Deparse
- CHI
- Carp
- Carp::Clan
- Catalyst::Action::RenderView
- Catalyst::Authentication::Store::DBIx::Class
- Catalyst::Component::ApplicationAttribute
- Catalyst::Controller
- Catalyst::Controller::AutoAssets
- Catalyst::Controller::SimpleCAS
- Catalyst::Devel
- Catalyst::Helper
- Catalyst::Helper::Model::DBIC::Schema
- Catalyst::Model
- Catalyst::Model::DBIC::Schema
- Catalyst::Plugin::Authorization::Roles
- Catalyst::Plugin::AutoAssets
- Catalyst::Plugin::Session::State::Cookie
- Catalyst::Plugin::Session::Store::DBIC
- Catalyst::Plugin::SimpleCAS
- Catalyst::Runtime
- Catalyst::ScriptRunner
- Catalyst::Test
- Catalyst::Utils
- Catalyst::View
- Catalyst::View::TT
- CatalystX::AppBuilder
- CatalystX::InjectComponent
- Class::Load
- Class::MOP::Class
- Clone
- Clone::PP
- DBD::SQLite
- DBI
- DBI::Const::GetInfoType
- DBIx::Class
- DBIx::Class::Core
- DBIx::Class::Helper::ResultSet::Util
- DBIx::Class::Helpers
- DBIx::Class::InflateColumn::Authen::Passphrase
- DBIx::Class::Optional::Dependencies
- DBIx::Class::ResultSet
- DBIx::Class::Schema
- DBIx::Class::Schema::Diff
- DBIx::Class::Schema::Loader
- DBIx::Class::Schema::Loader::DBI
- DBIx::Class::Schema::Loader::Table
- Data::Dumper
- Data::Dumper::Concise
- Data::Printer
- DateTime
- DateTime::Format::SQLite
- Digest::MD5
- Digest::SHA1
- Excel::Writer::XLSX
- Exporter
- File::Copy::Recursive
- File::ShareDir
- File::Spec
- File::Temp
- FindBin
- Getopt::Long
- HTML::Entities
- HTML::Parser
- HTML::TokeParser::Simple
- HTTP::Request::Common
- IPC::Cmd
- Import::Into
- JSON
- JSON::PP
- LWP::UserAgent
- List::MoreUtils
- List::Util
- MIME::Base64
- Module::Locate
- Module::Runtime
- Moo
- Moo::Role
- Moose
- Moose::Role
- Moose::Util::TypeConstraints
- MooseX::MarkAsMethods
- MooseX::NonMoose
- MooseX::Traits
- PPI
- Path::Class
- Perl::Tidy
- Plack
- Plack::Builder
- Plack::Component
- Plack::Middleware
- Plack::Runner
- Pod::Find
- Pod::Parser
- Pod::Usage
- SQL::Abstract
- SQL::Translator
- Scalar::Util
- Spreadsheet::ParseExcel
- Spreadsheet::ParseExcel::Utility
- Storable
- String::CamelCase
- String::Random
- Sub::Name
- Template
- Template::Context
- Template::Provider
- Term::ANSIColor
- Text::CSV
- Text::Glob
- Text::Markdown
- Text::SimpleTable::AutoWidth
- Text::TabularDisplay
- Text::WagnerFischer
- Tie::IxHash
- Time::HiRes
- Try::Tiny
- Type::Tiny
- Types::Standard
- URI
- URI::Escape
- autodie
- base
- bytes
- curry
- integer
- lib
- mro
- namespace::autoclean
- namespace::clean
- overload
- parent
- strict
- vars
- warnings
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Data::Dmap - just like map, but on deep data structures
VERSION
Version 0.08.
SYNOPSIS
This module provides the single function
dmap
which carries out amap
-like operation on deep data structures.use Data::Dmap; my $foo = { cars => [ 'ford', 'opel', 'BMW' ], birds => [ 'cuckatoo', 'ostrich', 'frigate' ], handler => sub { print "barf\n" } }; # This removes all keys named 'cars' my($bar) = dmap { delete $_->{cars} if ref eq 'HASH'; $_ } $foo; # This replaces arrays with the number of elements they contains my($other) = dmap { $_ = scalar @$_ if ref eq 'ARRAY'; $_ } $foo; use Data::Dumper; print Dumper $other; # # Prints # { # birds => 3, # handler => sub { "DUMMY" } # } # (Data::Dumper doesn't dump subs) $other->{handler}->(); # Prints # barf
EXPORTS
dmap
(always exported) - the dmap function that does deep in-place mappingcut
(optional) - a function for stopping recursion.
SUBROUTINES
dmap
This function works like
map
- it takes an expression followed by a list, evaluates the expression on each member of the list and returns the result.The only difference is that any references returned by the expression will also be traversed and passed to the expression once again, thus making it possible to make deep traversal of any data structure.
Objects (references blessed to something) are just traversed as if they weren't blessed.
Examples
Delete all hash references
use Data::Dmap; use Data::Dump 'pp'; pp dmap { return $_ unless ref eq 'HASH'; return; } 1, 'foo', [ { a => 1 }, 2]; # Prints: # (1, "foo", [2])
Delete every odd number
use Data::Dmap; use Data::Dump 'pp'; pp dmap { return if $_ % 2; $_ } [ 1 .. 10 ]; # Prints: # [2, 4, 6, 8, 10]
Replace all hash refs with some
$object
of classthingy
.use Data::Dmap; use Data::Dump 'pp'; pp dmap { return bless $_, 'thingy' if ref eq 'HASH'; $_ } [ 1, "hello", { a => 1 } ]; # Prints: # [1, "hello", bless({ a => 1 }, "thingy")]
dmap
understands what you want, if you return nothing (as opposed toundef
) when evaluating the expression for a hash key:use Data::Dmap; use Data::Dump 'pp; my $characters = { main => 'pooh', secondary => 'piglet' }; pp dmap { return if $_ eq "piglet"; $_ } $characters; # Prints: # { main => "pooh" }
Because the output from the expression is being traversed, you can use
dmap
to generate data structures:use Data::Dmap; use Data::Dump 'pp'; my $height = 3; pp dmap { if(ref eq 'HASH' and $height--) { $_->{a} = {height => $height} } $_ } {}; # Prints: # { # a => { # a => { # a => { # height => 0 # }, # height => 1 # }, # height => 2 # } # } # (My own formatting above.)
cut
The
cut
routine stops recursion at any point and returns any data as it is in place of the current node.Examples
use Data::Dmap 'cut'; use Data::Dump 'pp'; my $deep = { level => 1, data => { level => 2, data => { level => 3 } } }; pp dmap { cut('stop') if ref eq 'HASH' and $_->{level} == 2} $deep; # Prints: # # { data => { data => "stop", level => 2 }, level => 1 }
AUTHOR
Michael Zedeler,
<michael@zedeler.dk>
BUGS
If you find a bug, please consider helping to fix the bug by doing this:
Fork
Data::Dmap
from http://github.com/mzedeler/Data-DmapWrite a test case in the
t
directory, commit and push it.Fix the bug or (if you don't know how to fix it), report the bug
Bugs and feature requests can be reported through the web interface at http://github.com/mzedeler/Data-Dmap/issues. I may not be notified, so send me a mail too.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Data::Dmap
You can also look for information at:
The github issue tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
SEE ALSO
Data::Rmap, Data::Visitor, Data::Transformer, Data::Visitor, Data::Walk.
TODO
- Some kind of option making it possible to traverse objects with Class::MOP metaclasses, so we can avoid breaking encapsulation.
- Options to provide more information about the current node to the callback handler, such as path, depth and data types. Should not affect performance if not used.
LICENSE AND COPYRIGHT
Copyright 2010 Michael Zedeler.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
Module Install Instructions
To install RapidApp, copy and paste the appropriate command in to your terminal.
cpanm RapidApp
perl -MCPAN -e shell install RapidApp
For more information on module installation, please visit the detailed CPAN module installation guide.