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