| 1 | package Venus::Role::Dumpable; | ||||||||||
| 2 | |||||||||||
| 3 | 61 | ▶ | use 5.018; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 61 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 61 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 61 | ▶ | use Venus::Role 'with'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # METHODS | ||||||||||
| 11 | |||||||||||
| 12 | sub dump { | ||||||||||
| 13 | 1730 | ▶ | my ($self, $method, @args) = @_; | ||||||||
|
Subroutine
dump: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | |||||||||||
| 15 | 1730 | require Data::Dumper; | |||||||||
| 16 | |||||||||||
| 17 | 61 | ▶ | no warnings 'once'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 1730 | local $Data::Dumper::Indent = 0; | |||||||||
| 20 | 1730 | local $Data::Dumper::Purity = 0; | |||||||||
| 21 | 1730 | local $Data::Dumper::Quotekeys = 0; | |||||||||
| 22 | 1730 | local $Data::Dumper::Deepcopy = 1; | |||||||||
| 23 | 1730 | local $Data::Dumper::Deparse = 1; | |||||||||
| 24 | 1730 | local $Data::Dumper::Sortkeys = 1; | |||||||||
| 25 | 1730 | local $Data::Dumper::Terse = 1; | |||||||||
| 26 | 1730 | local $Data::Dumper::Useqq = 1; | |||||||||
| 27 | |||||||||||
| 28 | 1730 | ▶ | my $data = Data::Dumper->Dump([ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | $method ? scalar($self->$method(@args)) : $self | ||||||||||
| 30 | ]); | ||||||||||
| 31 | |||||||||||
| 32 | 1730 | $data =~ s/^"|"$//g; | |||||||||
| 33 | |||||||||||
| 34 | 1730 | return $data; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub dump_pretty { | ||||||||||
| 38 | 5 | ▶ | my ($self, $method, @args) = @_; | ||||||||
|
Subroutine
dump_pretty: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 39 | |||||||||||
| 40 | 5 | require Data::Dumper; | |||||||||
| 41 | |||||||||||
| 42 | 61 | ▶ | no warnings 'once'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | |||||||||||
| 44 | 5 | local $Data::Dumper::Indent = 2; | |||||||||
| 45 | 5 | local $Data::Dumper::Trailingcomma = 0; | |||||||||
| 46 | 5 | local $Data::Dumper::Purity = 0; | |||||||||
| 47 | 5 | local $Data::Dumper::Pad = ''; | |||||||||
| 48 | 5 | local $Data::Dumper::Varname = 'VAR'; | |||||||||
| 49 | 5 | local $Data::Dumper::Useqq = 0; | |||||||||
| 50 | 5 | local $Data::Dumper::Terse = 1; | |||||||||
| 51 | 5 | local $Data::Dumper::Freezer = ''; | |||||||||
| 52 | 5 | local $Data::Dumper::Toaster = ''; | |||||||||
| 53 | 5 | local $Data::Dumper::Deepcopy = 1; | |||||||||
| 54 | 5 | local $Data::Dumper::Quotekeys = 0; | |||||||||
| 55 | 5 | local $Data::Dumper::Bless = 'bless'; | |||||||||
| 56 | 5 | local $Data::Dumper::Pair = ' => '; | |||||||||
| 57 | 5 | local $Data::Dumper::Maxdepth = 0; | |||||||||
| 58 | 5 | local $Data::Dumper::Maxrecurse = 1000; | |||||||||
| 59 | 5 | local $Data::Dumper::Useperl = 0; | |||||||||
| 60 | 5 | local $Data::Dumper::Sortkeys = 1; | |||||||||
| 61 | 5 | local $Data::Dumper::Deparse = 1; | |||||||||
| 62 | 5 | local $Data::Dumper::Sparseseen = 0; | |||||||||
| 63 | |||||||||||
| 64 | 5 | ▶ | my $data = Data::Dumper->Dump([ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | $method ? scalar($self->$method(@args)) : $self | ||||||||||
| 66 | ]); | ||||||||||
| 67 | |||||||||||
| 68 | 5 | $data =~ s/^'|'$//g; | |||||||||
| 69 | |||||||||||
| 70 | 5 | chomp $data; | |||||||||
| 71 | |||||||||||
| 72 | 5 | return $data; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | # EXPORTS | ||||||||||
| 76 | |||||||||||
| 77 | sub EXPORT { | ||||||||||
| 78 | 185 | ▶ | ['dump', 'dump_pretty'] | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 61 | 1; | |||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | =head1 NAME | ||||||||||
| 86 | |||||||||||
| 87 | Venus::Role::Dumpable - Dumpable Role | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | =head1 ABSTRACT | ||||||||||
| 92 | |||||||||||
| 93 | Dumpable Role for Perl 5 | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | =head1 SYNOPSIS | ||||||||||
| 98 | |||||||||||
| 99 | package Example; | ||||||||||
| 100 | |||||||||||
| 101 | use Venus::Class; | ||||||||||
| 102 | |||||||||||
| 103 | attr 'test'; | ||||||||||
| 104 | |||||||||||
| 105 | with 'Venus::Role::Dumpable'; | ||||||||||
| 106 | |||||||||||
| 107 | package main; | ||||||||||
| 108 | |||||||||||
| 109 | my $example = Example->new(test => 123); | ||||||||||
| 110 | |||||||||||
| 111 | # $example->dump; | ||||||||||
| 112 | |||||||||||
| 113 | =cut | ||||||||||
| 114 | |||||||||||
| 115 | =head1 DESCRIPTION | ||||||||||
| 116 | |||||||||||
| 117 | This package modifies the consuming package and provides methods for dumping | ||||||||||
| 118 | the object or the return value of a dispatched method call. | ||||||||||
| 119 | |||||||||||
| 120 | =cut | ||||||||||
| 121 | |||||||||||
| 122 | =head1 METHODS | ||||||||||
| 123 | |||||||||||
| 124 | This package provides the following methods: | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||
| 127 | |||||||||||
| 128 | =head2 dump | ||||||||||
| 129 | |||||||||||
| 130 | dump(Str | CodeRef $method, Any @args) (Str) | ||||||||||
| 131 | |||||||||||
| 132 | The dump method returns a string representation of the underlying data. This | ||||||||||
| 133 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||
| 134 | return value will be acted on by this method. | ||||||||||
| 135 | |||||||||||
| 136 | I<Since C<0.01>> | ||||||||||
| 137 | |||||||||||
| 138 | =over 4 | ||||||||||
| 139 | |||||||||||
| 140 | =item dump example 1 | ||||||||||
| 141 | |||||||||||
| 142 | package main; | ||||||||||
| 143 | |||||||||||
| 144 | my $example = Example->new(test => 123); | ||||||||||
| 145 | |||||||||||
| 146 | my $dump = $example->dump; | ||||||||||
| 147 | |||||||||||
| 148 | # "bless( {test => 123}, 'Example' )" | ||||||||||
| 149 | |||||||||||
| 150 | =back | ||||||||||
| 151 | |||||||||||
| 152 | =cut | ||||||||||
| 153 | |||||||||||
| 154 | =head2 dump_pretty | ||||||||||
| 155 | |||||||||||
| 156 | dump_pretty(Str | CodeRef $method, Any @args) (Str) | ||||||||||
| 157 | |||||||||||
| 158 | The dump_pretty method returns a string representation of the underlying data | ||||||||||
| 159 | that is human-readable and useful for debugging. This method supports | ||||||||||
| 160 | dispatching, i.e. providing a method name and arguments whose return value will | ||||||||||
| 161 | be acted on by this method. | ||||||||||
| 162 | |||||||||||
| 163 | I<Since C<0.01>> | ||||||||||
| 164 | |||||||||||
| 165 | =over 4 | ||||||||||
| 166 | |||||||||||
| 167 | =item dump_pretty example 1 | ||||||||||
| 168 | |||||||||||
| 169 | package main; | ||||||||||
| 170 | |||||||||||
| 171 | my $example = Example->new(test => 123); | ||||||||||
| 172 | |||||||||||
| 173 | my $dump_pretty = $example->dump_pretty; | ||||||||||
| 174 | |||||||||||
| 175 | # bless( { | ||||||||||
| 176 | # test => 123 | ||||||||||
| 177 | # }, 'Example' ) | ||||||||||
| 178 | |||||||||||
| 179 | =back | ||||||||||
| 180 | |||||||||||
| 181 | =cut | ||||||||||