Data-Censor
view release on metacpan or search on metacpan
lib/Data/Censor.pm view on Meta::CPAN
package Data::Censor;
use 5.006;
use strict;
use warnings FATAL => 'all';
use Carp;
use Ref::Util qw/ is_hashref /;
=head1 NAME
Data::Censor - censor sensitive stuff in a data structure
=head1 VERSION
Version 0.04
=cut
our $VERSION = '0.04';
=head1 SYNOPSIS
# OO way, letting you specify your own list of sensitive-looking fields, and
# what they should be replaced by (all options here are optional)
my $censor = Data::Censor->new(
# Specify which fields to censor:
sensitive_fields => [ qw(card_number password) ],
# Specify text to replace their values with:
replacement => '(Sensitive data hidden)',
# Or specify callbacks for each field name which return the "censored"
# value - in this case, masking a card number (PAN) to show only the
# last four digits:
replacement_callbacks => {
card_number => sub {
my $pan = shift;
return "x" x (length($pan) - 4) . substr($pan, -4, 4);
},
},
);
# Censor the data in-place (changes the data structure, returns the number
# of keys censored)
my $censor_count = $censor->censor(\%data);
# Alternate non-OO interface, using default settings and returning a cloned
# version of the data after censoring:
my $censored_data = Data::Censor->clone_and_censor(\%data);
=head1 new (CONSTRUCTOR)
Accepts the following arguments:
=over
=item sensitive_fields
Either an arrayref of sensitive fields, checked for equality, or a regex to test
against each key to see if it's considered sensitive.
=item replacement
The string to replace each value with. Any censoring callback provided in
C<replacement_callbacks> which matches this key will take precedence over this
( run in 1.451 second using v1.01-cache-2.11-cpan-39bf76dae61 )