@@ -82,17 +82,14 @@ has censor => (
82
82
return eval ' \&' .$custom ;
83
83
}
84
84
85
- # once Data::Censor has been updated with https://github.com/bigpresh/Data-Censor/pull/2
86
- # my $data_censor = use_module('Data::Censor')->new(
87
- # sensitive_fields => qr/pass|card?num|pan|secret/i,
88
- # replacement => "Hidden (looks potentially sensitive)",
89
- # );
90
-
91
- # return sub {
92
- # $data_censor->censor(@_);
93
- # };
94
-
95
- return \&_censor;
85
+ my $data_censor = use_module(' Data::Censor' )-> new(
86
+ sensitive_fields => qr / pass|card?num|pan|secret/ i ,
87
+ replacement => " Hidden (looks potentially sensitive)" ,
88
+ );
89
+
90
+ return sub {
91
+ $data_censor -> censor(@_ );
92
+ };
96
93
}
97
94
);
98
95
@@ -471,37 +468,6 @@ sub get_caller {
471
468
472
469
# private
473
470
474
- # Given a hashref, censor anything that looks sensitive. Returns number of
475
- # items which were "censored".
476
-
477
- sub _censor {
478
- my $hash = shift ;
479
- my $visited = shift || {};
480
-
481
- unless ( $hash && is_hashref($hash ) ) {
482
- carp " _censor given incorrect input: $hash " ;
483
- return ;
484
- }
485
-
486
- my $censored = 0;
487
- for my $key ( keys %$hash ) {
488
- if ( is_hashref( $hash -> {$key } ) ) {
489
- if (!$visited -> { $hash -> {$key } }) {
490
- # mark the new ref as visited
491
- $visited -> { $hash -> {$key } } = 1;
492
-
493
- $censored += _censor( $hash -> {$key }, $visited );
494
- }
495
- }
496
- elsif ( $key =~ / (pass|card?num|pan|secret)/i ) {
497
- $hash -> {$key } = " Hidden (looks potentially sensitive)" ;
498
- $censored ++;
499
- }
500
- }
501
-
502
- return $censored ;
503
- }
504
-
505
471
# Replaces the entities that are illegal in (X)HTML.
506
472
sub _html_encode {
507
473
my $value = shift ;
@@ -573,12 +539,22 @@ The message of the error page.
573
539
574
540
=attr censor
575
541
576
- The function to use to censor error messages. By default it uses the
577
- C<_censor > function of this package, but it can be configured via the
578
- app setting 'error_censor'. If provided, C<error_censor > has to be
579
- the fully qualified name of the censor function to use. That function is
580
- expected to take in the data as a hashref, modify it in place and return
581
- the number of items 'censored'.
542
+ The function to use to censor error messages. By default it uses the C<censor > method of L<Data::Censor> C<_censor > "
543
+
544
+ # default censor function used by `error_censor`
545
+ # is equivalent to
546
+ sub MyApp::censor {
547
+ Data::Censor->new(
548
+ sensitive_fields => qr/pass|card?num|pan|secret/i,
549
+ replacement => "Hidden (looks potentially sensitive)",
550
+ )->censor(@_);
551
+ }
552
+ setting error_censor => 'MyApp::censor';
553
+
554
+ It can be configured via the app setting C<error_censor > . If provided,
555
+ C<error_censor > has to be the fully qualified name of the censor
556
+ function. That function is expected to take in the data as a hashref,
557
+ modify it in place and return the number of items 'censored'.
582
558
583
559
For example, using L<Data::Censor> .
584
560
@@ -613,6 +589,8 @@ L<Data::Censor> above could also have been done via the config
613
589
- hush
614
590
replacement: '(Sensitive data hidden)'
615
591
592
+
593
+
616
594
=method throw($response)
617
595
618
596
Populates the content of the response with the error's information.
0 commit comments