File Coverage

blib/lib/Reply/Plugin/DataDumperAutoEncode.pm
Criterion Covered Total %
statement 21 47 44.6
branch 0 14 0.0
condition n/a
subroutine 7 12 58.3
pod 4 5 80.0
total 32 78 41.0


line stmt bran cond sub pod time code
1             package Reply::Plugin::DataDumperAutoEncode;
2 1     1   929 use 5.008005;
  1         3  
  1         45  
3 1     1   6 use strict;
  1         2  
  1         34  
4 1     1   5 use warnings;
  1         11  
  1         52  
5              
6             our $VERSION = "0.02";
7              
8 1     1   923 use parent 'Reply::Plugin';
  1         387  
  1         6  
9              
10 1     1   82985 use Data::Dumper;
  1         10156  
  1         93  
11 1     1   5995 use Data::Dumper::AutoEncode;
  1         42933  
  1         134  
12              
13             my $enable_auto_encode = 1;
14              
15             sub new {
16 0     0 0   my $class = shift;
17              
18 0           $Data::Dumper::Terse = 1;
19 0           $Data::Dumper::Sortkeys = 1;
20              
21 0           my @subs = ('enable_auto_encode', 'disable_auto_encode');
22 0           for my $sub_name ( @subs ) {
23 1     1   24 no strict 'refs';
  1         2  
  1         1130  
24 0           *{ 'main::' . $sub_name } = \&{ $sub_name };
  0            
  0            
25             }
26              
27 0           return $class->SUPER::new( @_, subs => \@subs );
28             }
29              
30             sub mangle_result {
31 0     0 1   my $self = shift;
32 0           my (@result_in) = @_;
33              
34 0 0         my @result = @result_in == 0 ? () : @result_in == 1 ? $result_in[0] : \@result_in;
    0          
35 0 0         if ( $enable_auto_encode ) {
36 0           return eDumper(@result);
37             }
38             else {
39 0           return Dumper(@result);
40             }
41             }
42              
43             sub tab_handler {
44 0     0 1   my $self = shift;
45 0           my ($line) = @_;
46              
47 0 0         return if length $line <= 0;
48 0 0         return if $line =~ /^#/; # command
49 0 0         return if $line =~ /->\s*$/; # method call
50 0 0         return if $line =~ /[\$\@\%\&\*]\s*$/;
51              
52 0           return sort grep { index($_, $line) == 0 } @{ $self->{subs} };
  0            
  0            
53             }
54              
55 0     0 1   sub enable_auto_encode { $enable_auto_encode = 1; }
56 0     0 1   sub disable_auto_encode { $enable_auto_encode = 0; }
57              
58              
59              
60             1;
61             __END__
62              
63             =encoding utf-8
64              
65             =head1 NAME
66              
67             Reply::Plugin::DataDumperAutoEncode - format and decode results using Data::Dumper::AutoEncode
68              
69             =head1 SYNOPSIS
70              
71             ; in your .replyrc use following instead of [DataDumper]
72             [DataDumperAutoEncode]
73              
74             =head1 DESCRIPTION
75              
76             Reply::Plugin::DataDumperAutoEncode uses L<Data::Dumper::AutoEncode> to format and encode results.
77             Results of L<Data::Dumper> has decoded string, it is hard to read for human. Using this plugin
78             instead of L<Reply::Plugin::DataDumper>, results are automatically decoded and easy to read for human.
79              
80             =head1 METHODS
81              
82             =head2 enable_auto_encode()
83              
84             enables auto encode. auto encode is enabled by default.
85              
86             =head2 disable_auto_encode()
87              
88             disables auto encode
89              
90             =head1 SEE ALSO
91              
92             L<Reply::Plugin::DataDumper>, L<Data::Dumper::AutoEncode>
93              
94             =head1 LICENSE
95              
96             Copyright (C) Takuya Tsuchida.
97              
98             This library is free software; you can redistribute it and/or modify
99             it under the same terms as Perl itself.
100              
101             =head1 AUTHOR
102              
103             Takuya Tsuchida E<lt>tsucchi@cpan.orgE<gt>
104              
105             =cut
106