| 1 | package Venus::Role::Printable; | ||||||||||
| 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 'fault'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # AUDITS | ||||||||||
| 13 | |||||||||||
| 14 | 129 | ▶ | sub AUDIT { | ||||||||
|
Subroutine
AUDIT: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 15 | 129 | my ($self, $from) = @_; | |||||||||
| 16 | |||||||||||
| 17 | 129 | ▶ | if (!$from->does('Venus::Role::Dumpable')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 0 | fault "${self} requires ${from} to consume Venus::Role::Dumpable"; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 129 | return $self; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | # METHODS | ||||||||||
| 25 | |||||||||||
| 26 | 2 | ▶ | sub print { | ||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 2 | my ($self, @args) = @_; | |||||||||
| 28 | |||||||||||
| 29 | 2 | return $self->printer($self->dump(@args)); | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 2 | ▶ | sub print_json { | ||||||||
|
Subroutine
print_json: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 33 | 2 | my ($self, $method, @args) = @_; | |||||||||
| 34 | |||||||||||
| 35 | 2 | require Venus::Json; | |||||||||
| 36 | |||||||||||
| 37 | 2 | ▶ | my $value = $method ? scalar($self->$method(@args)) : $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 2 | require Scalar::Util; | |||||||||
| 40 | |||||||||||
| 41 | 2 | ▶ | if (Scalar::Util::blessed($value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 1 | ▶ | $value = $value->value if $value->isa('Venus::Kind'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 2 | return $self->printer(Venus::Json->new($value)->encode); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | ▶ | sub print_pretty { | ||||||||
|
Subroutine
print_pretty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 2 | my ($self, @args) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 2 | return $self->printer($self->dump_pretty(@args)); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 1 | ▶ | sub print_string { | ||||||||
|
Subroutine
print_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 55 | 1 | my ($self, $method, @args) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 1 | local $_ = $self; | |||||||||
| 58 | |||||||||||
| 59 | 1 | ▶ | return $self->printer($method ? scalar($self->$method(@args)) : $self); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | ▶ | sub print_yaml { | ||||||||
|
Subroutine
print_yaml: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 63 | 2 | my ($self, $method, @args) = @_; | |||||||||
| 64 | |||||||||||
| 65 | 2 | require Venus::Yaml; | |||||||||
| 66 | |||||||||||
| 67 | 2 | ▶ | my $value = $method ? scalar($self->$method(@args)) : $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | 2 | require Scalar::Util; | |||||||||
| 70 | |||||||||||
| 71 | 2 | ▶ | if (Scalar::Util::blessed($value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 1 | ▶ | $value = $value->value if $value->isa('Venus::Kind'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 2 | return $self->printer(Venus::Yaml->new($value)->encode); | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub printer { | ||||||||
|
Subroutine
printer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 79 | 0 | my ($self, @args) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 0 | require Venus::Os; | |||||||||
| 82 | |||||||||||
| 83 | 0 | Venus::Os->new->write('STDOUT', join '', @args); | |||||||||
| 84 | |||||||||||
| 85 | 0 | return true; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 2 | ▶ | sub say { | ||||||||
|
Subroutine
say: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 89 | 2 | my ($self, @args) = @_; | |||||||||
| 90 | |||||||||||
| 91 | 2 | return $self->printer($self->dump(@args), "\n"); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 2 | ▶ | sub say_json { | ||||||||
|
Subroutine
say_json: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 95 | 2 | my ($self, $method, @args) = @_; | |||||||||
| 96 | |||||||||||
| 97 | 2 | require Venus::Json; | |||||||||
| 98 | |||||||||||
| 99 | 2 | ▶ | my $value = $method ? scalar($self->$method(@args)) : $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | |||||||||||
| 101 | 2 | require Scalar::Util; | |||||||||
| 102 | |||||||||||
| 103 | 2 | ▶ | if (Scalar::Util::blessed($value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 1 | ▶ | $value = $value->value if $value->isa('Venus::Kind'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 2 | return $self->printer(Venus::Json->new($value)->encode, "\n"); | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 2 | ▶ | sub say_pretty { | ||||||||
|
Subroutine
say_pretty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 111 | 2 | my ($self, @args) = @_; | |||||||||
| 112 | |||||||||||
| 113 | 2 | return $self->printer($self->dump_pretty(@args), "\n"); | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 1 | ▶ | sub say_string { | ||||||||
|
Subroutine
say_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 117 | 1 | my ($self, $method, @args) = @_; | |||||||||
| 118 | |||||||||||
| 119 | 1 | local $_ = $self; | |||||||||
| 120 | |||||||||||
| 121 | 1 | ▶ | return $self->printer(($method ? scalar($self->$method(@args)) : $self), "\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 2 | ▶ | sub say_yaml { | ||||||||
|
Subroutine
say_yaml: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 125 | 2 | my ($self, $method, @args) = @_; | |||||||||
| 126 | |||||||||||
| 127 | 2 | require Venus::Yaml; | |||||||||
| 128 | |||||||||||
| 129 | 2 | ▶ | my $value = $method ? scalar($self->$method(@args)) : $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | |||||||||||
| 131 | 2 | require Scalar::Util; | |||||||||
| 132 | |||||||||||
| 133 | 2 | ▶ | if (Scalar::Util::blessed($value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | 1 | ▶ | $value = $value->value if $value->isa('Venus::Kind'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 2 | return $self->printer(Venus::Yaml->new($value)->encode, "\n"); | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | # EXPORTS | ||||||||||
| 141 | |||||||||||
| 142 | 129 | ▶ | sub EXPORT { | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 143 | [ | ||||||||||
| 144 | 129 | 'print', | |||||||||
| 145 | 'print_json', | ||||||||||
| 146 | 'print_pretty', | ||||||||||
| 147 | 'print_string', | ||||||||||
| 148 | 'print_yaml', | ||||||||||
| 149 | 'printer', | ||||||||||
| 150 | 'say', | ||||||||||
| 151 | 'say_json', | ||||||||||
| 152 | 'say_pretty', | ||||||||||
| 153 | 'say_string', | ||||||||||
| 154 | 'say_yaml', | ||||||||||
| 155 | ] | ||||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | 119 | 1; | |||||||||
| 159 | |||||||||||
| 160 | |||||||||||
| 161 | |||||||||||
| 162 | =head1 NAME | ||||||||||
| 163 | |||||||||||
| 164 | Venus::Role::Printable - Printable Role | ||||||||||
| 165 | |||||||||||
| 166 | =cut | ||||||||||
| 167 | |||||||||||
| 168 | =head1 ABSTRACT | ||||||||||
| 169 | |||||||||||
| 170 | Printable Role for Perl 5 | ||||||||||
| 171 | |||||||||||
| 172 | =cut | ||||||||||
| 173 | |||||||||||
| 174 | =head1 SYNOPSIS | ||||||||||
| 175 | |||||||||||
| 176 | package Example; | ||||||||||
| 177 | |||||||||||
| 178 | use Venus::Class; | ||||||||||
| 179 | |||||||||||
| 180 | with 'Venus::Role::Dumpable'; | ||||||||||
| 181 | with 'Venus::Role::Printable'; | ||||||||||
| 182 | |||||||||||
| 183 | attr 'test'; | ||||||||||
| 184 | |||||||||||
| 185 | sub execute { | ||||||||||
| 186 | return [@_]; | ||||||||||
| 187 | } | ||||||||||
| 188 | |||||||||||
| 189 | sub printer { | ||||||||||
| 190 | return [@_]; | ||||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | package main; | ||||||||||
| 194 | |||||||||||
| 195 | my $example = Example->new(test => 123); | ||||||||||
| 196 | |||||||||||
| 197 | # $example->say; | ||||||||||
| 198 | |||||||||||
| 199 | =cut | ||||||||||
| 200 | |||||||||||
| 201 | =head1 DESCRIPTION | ||||||||||
| 202 | |||||||||||
| 203 | This package provides a mechanism for outputting (printing) objects or the | ||||||||||
| 204 | return value of a dispatched method call to STDOUT. | ||||||||||
| 205 | |||||||||||
| 206 | =cut | ||||||||||
| 207 | |||||||||||
| 208 | =head1 METHODS | ||||||||||
| 209 | |||||||||||
| 210 | This package provides the following methods: | ||||||||||
| 211 | |||||||||||
| 212 | =cut | ||||||||||
| 213 | |||||||||||
| 214 | =head2 print | ||||||||||
| 215 | |||||||||||
| 216 | print(any @data) (any) | ||||||||||
| 217 | |||||||||||
| 218 | The print method prints a stringified representation of the underlying data. | ||||||||||
| 219 | |||||||||||
| 220 | I<Since C<0.01>> | ||||||||||
| 221 | |||||||||||
| 222 | =over 4 | ||||||||||
| 223 | |||||||||||
| 224 | =item print example 1 | ||||||||||
| 225 | |||||||||||
| 226 | package main; | ||||||||||
| 227 | |||||||||||
| 228 | my $example = Example->new(test => 123); | ||||||||||
| 229 | |||||||||||
| 230 | my $print = $example->print; | ||||||||||
| 231 | |||||||||||
| 232 | # bless({test => 123}, 'Example') | ||||||||||
| 233 | |||||||||||
| 234 | # 1 | ||||||||||
| 235 | |||||||||||
| 236 | =back | ||||||||||
| 237 | |||||||||||
| 238 | =over 4 | ||||||||||
| 239 | |||||||||||
| 240 | =item print example 2 | ||||||||||
| 241 | |||||||||||
| 242 | package main; | ||||||||||
| 243 | |||||||||||
| 244 | my $example = Example->new(test => 123); | ||||||||||
| 245 | |||||||||||
| 246 | my $print = $example->print('execute', 1, 2, 3); | ||||||||||
| 247 | |||||||||||
| 248 | # [bless({test => 123}, 'Example'),1,2,3] | ||||||||||
| 249 | |||||||||||
| 250 | # 1 | ||||||||||
| 251 | |||||||||||
| 252 | =back | ||||||||||
| 253 | |||||||||||
| 254 | =cut | ||||||||||
| 255 | |||||||||||
| 256 | =head2 print_json | ||||||||||
| 257 | |||||||||||
| 258 | print_json(string | coderef $method, any @args) (any) | ||||||||||
| 259 | |||||||||||
| 260 | The print_json method prints a JSON representation of the underlying data. This | ||||||||||
| 261 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||
| 262 | return value will be acted on by this method. | ||||||||||
| 263 | |||||||||||
| 264 | I<Since C<2.91>> | ||||||||||
| 265 | |||||||||||
| 266 | =over 4 | ||||||||||
| 267 | |||||||||||
| 268 | =item print_json example 1 | ||||||||||
| 269 | |||||||||||
| 270 | package main; | ||||||||||
| 271 | |||||||||||
| 272 | my $example = Example->new(test => 123); | ||||||||||
| 273 | |||||||||||
| 274 | my $print_json = $example->print_json; | ||||||||||
| 275 | |||||||||||
| 276 | # "{\"test\": 123}" | ||||||||||
| 277 | |||||||||||
| 278 | =back | ||||||||||
| 279 | |||||||||||
| 280 | =over 4 | ||||||||||
| 281 | |||||||||||
| 282 | =item print_json example 2 | ||||||||||
| 283 | |||||||||||
| 284 | package main; | ||||||||||
| 285 | |||||||||||
| 286 | my $example = Example->new(test => 123); | ||||||||||
| 287 | |||||||||||
| 288 | my $print_json = $example->print_json('execute'); | ||||||||||
| 289 | |||||||||||
| 290 | # "[{\"test\": 123}]" | ||||||||||
| 291 | |||||||||||
| 292 | =back | ||||||||||
| 293 | |||||||||||
| 294 | =cut | ||||||||||
| 295 | |||||||||||
| 296 | =head2 print_pretty | ||||||||||
| 297 | |||||||||||
| 298 | print_pretty(any @data) (any) | ||||||||||
| 299 | |||||||||||
| 300 | The print_pretty method prints a stringified human-readable representation of | ||||||||||
| 301 | the underlying data. | ||||||||||
| 302 | |||||||||||
| 303 | I<Since C<0.01>> | ||||||||||
| 304 | |||||||||||
| 305 | =over 4 | ||||||||||
| 306 | |||||||||||
| 307 | =item print_pretty example 1 | ||||||||||
| 308 | |||||||||||
| 309 | package main; | ||||||||||
| 310 | |||||||||||
| 311 | my $example = Example->new(test => 123); | ||||||||||
| 312 | |||||||||||
| 313 | my $print_pretty = $example->print_pretty; | ||||||||||
| 314 | |||||||||||
| 315 | # bless({ test => 123 }, 'Example') | ||||||||||
| 316 | |||||||||||
| 317 | # 1 | ||||||||||
| 318 | |||||||||||
| 319 | =back | ||||||||||
| 320 | |||||||||||
| 321 | =over 4 | ||||||||||
| 322 | |||||||||||
| 323 | =item print_pretty example 2 | ||||||||||
| 324 | |||||||||||
| 325 | package main; | ||||||||||
| 326 | |||||||||||
| 327 | my $example = Example->new(test => 123); | ||||||||||
| 328 | |||||||||||
| 329 | my $print_pretty = $example->print_pretty('execute', 1, 2, 3); | ||||||||||
| 330 | |||||||||||
| 331 | # [ | ||||||||||
| 332 | # bless({ test => 123 }, 'Example'), | ||||||||||
| 333 | # 1, | ||||||||||
| 334 | # 2, | ||||||||||
| 335 | # 3 | ||||||||||
| 336 | # ] | ||||||||||
| 337 | |||||||||||
| 338 | # 1 | ||||||||||
| 339 | |||||||||||
| 340 | =back | ||||||||||
| 341 | |||||||||||
| 342 | =cut | ||||||||||
| 343 | |||||||||||
| 344 | =head2 print_string | ||||||||||
| 345 | |||||||||||
| 346 | print_string(string | coderef $method, any @args) (any) | ||||||||||
| 347 | |||||||||||
| 348 | The print_string method prints a string representation of the underlying data | ||||||||||
| 349 | without using a dump. This method supports dispatching, i.e. providing a | ||||||||||
| 350 | method name and arguments whose return value will be acted on by this method. | ||||||||||
| 351 | |||||||||||
| 352 | I<Since C<0.09>> | ||||||||||
| 353 | |||||||||||
| 354 | =over 4 | ||||||||||
| 355 | |||||||||||
| 356 | =item print_string example 1 | ||||||||||
| 357 | |||||||||||
| 358 | package main; | ||||||||||
| 359 | |||||||||||
| 360 | my $example = Example->new(test => 123); | ||||||||||
| 361 | |||||||||||
| 362 | my $print_string = $example->print_string; | ||||||||||
| 363 | |||||||||||
| 364 | # 'Example' | ||||||||||
| 365 | |||||||||||
| 366 | # 1 | ||||||||||
| 367 | |||||||||||
| 368 | =back | ||||||||||
| 369 | |||||||||||
| 370 | =cut | ||||||||||
| 371 | |||||||||||
| 372 | =head2 print_yaml | ||||||||||
| 373 | |||||||||||
| 374 | print_yaml(string | coderef $method, any @args) (any) | ||||||||||
| 375 | |||||||||||
| 376 | The print_yaml method prints a YAML representation of the underlying data. This | ||||||||||
| 377 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||
| 378 | return value will be acted on by this method. | ||||||||||
| 379 | |||||||||||
| 380 | I<Since C<2.91>> | ||||||||||
| 381 | |||||||||||
| 382 | =over 4 | ||||||||||
| 383 | |||||||||||
| 384 | =item print_yaml example 1 | ||||||||||
| 385 | |||||||||||
| 386 | package main; | ||||||||||
| 387 | |||||||||||
| 388 | my $example = Example->new(test => 123); | ||||||||||
| 389 | |||||||||||
| 390 | my $print_yaml = $example->print_yaml; | ||||||||||
| 391 | |||||||||||
| 392 | # "---\ntest: 123" | ||||||||||
| 393 | |||||||||||
| 394 | =back | ||||||||||
| 395 | |||||||||||
| 396 | =over 4 | ||||||||||
| 397 | |||||||||||
| 398 | =item print_yaml example 2 | ||||||||||
| 399 | |||||||||||
| 400 | package main; | ||||||||||
| 401 | |||||||||||
| 402 | my $example = Example->new(test => 123); | ||||||||||
| 403 | |||||||||||
| 404 | my $print_yaml = $example->print_yaml('execute'); | ||||||||||
| 405 | |||||||||||
| 406 | # "---\n- test: 123" | ||||||||||
| 407 | |||||||||||
| 408 | =back | ||||||||||
| 409 | |||||||||||
| 410 | =cut | ||||||||||
| 411 | |||||||||||
| 412 | =head2 say | ||||||||||
| 413 | |||||||||||
| 414 | say(any @data) (any) | ||||||||||
| 415 | |||||||||||
| 416 | The say method prints a stringified representation of the underlying data, with | ||||||||||
| 417 | a trailing newline. | ||||||||||
| 418 | |||||||||||
| 419 | I<Since C<0.01>> | ||||||||||
| 420 | |||||||||||
| 421 | =over 4 | ||||||||||
| 422 | |||||||||||
| 423 | =item say example 1 | ||||||||||
| 424 | |||||||||||
| 425 | package main; | ||||||||||
| 426 | |||||||||||
| 427 | my $example = Example->new(test => 123); | ||||||||||
| 428 | |||||||||||
| 429 | my $say = $example->say; | ||||||||||
| 430 | |||||||||||
| 431 | # bless({test => 123}, 'Example')\n | ||||||||||
| 432 | |||||||||||
| 433 | # 1 | ||||||||||
| 434 | |||||||||||
| 435 | =back | ||||||||||
| 436 | |||||||||||
| 437 | =over 4 | ||||||||||
| 438 | |||||||||||
| 439 | =item say example 2 | ||||||||||
| 440 | |||||||||||
| 441 | package main; | ||||||||||
| 442 | |||||||||||
| 443 | my $example = Example->new(test => 123); | ||||||||||
| 444 | |||||||||||
| 445 | my $say = $example->say; | ||||||||||
| 446 | |||||||||||
| 447 | # [bless({test => 123}, 'Example'),1,2,3]\n | ||||||||||
| 448 | |||||||||||
| 449 | # 1 | ||||||||||
| 450 | |||||||||||
| 451 | =back | ||||||||||
| 452 | |||||||||||
| 453 | =cut | ||||||||||
| 454 | |||||||||||
| 455 | =head2 say_json | ||||||||||
| 456 | |||||||||||
| 457 | say_json(string | coderef $method, any @args) (any) | ||||||||||
| 458 | |||||||||||
| 459 | The say_json method prints a JSON representation of the underlying data. This | ||||||||||
| 460 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||
| 461 | return value will be acted on by this method, with a trailing newline. | ||||||||||
| 462 | |||||||||||
| 463 | I<Since C<2.91>> | ||||||||||
| 464 | |||||||||||
| 465 | =over 4 | ||||||||||
| 466 | |||||||||||
| 467 | =item say_json example 1 | ||||||||||
| 468 | |||||||||||
| 469 | package main; | ||||||||||
| 470 | |||||||||||
| 471 | my $example = Example->new(test => 123); | ||||||||||
| 472 | |||||||||||
| 473 | my $say_json = $example->say_json; | ||||||||||
| 474 | |||||||||||
| 475 | # "{\"test\": 123}\n" | ||||||||||
| 476 | |||||||||||
| 477 | =back | ||||||||||
| 478 | |||||||||||
| 479 | =over 4 | ||||||||||
| 480 | |||||||||||
| 481 | =item say_json example 2 | ||||||||||
| 482 | |||||||||||
| 483 | package main; | ||||||||||
| 484 | |||||||||||
| 485 | my $example = Example->new(test => 123); | ||||||||||
| 486 | |||||||||||
| 487 | my $say_json = $example->say_json('execute'); | ||||||||||
| 488 | |||||||||||
| 489 | # "[{\"test\": 123}]\n" | ||||||||||
| 490 | |||||||||||
| 491 | =back | ||||||||||
| 492 | |||||||||||
| 493 | =cut | ||||||||||
| 494 | |||||||||||
| 495 | =head2 say_pretty | ||||||||||
| 496 | |||||||||||
| 497 | say_pretty(any @data) (any) | ||||||||||
| 498 | |||||||||||
| 499 | The say_pretty method prints a stringified human-readable representation of the | ||||||||||
| 500 | underlying data, with a trailing newline. | ||||||||||
| 501 | |||||||||||
| 502 | I<Since C<0.01>> | ||||||||||
| 503 | |||||||||||
| 504 | =over 4 | ||||||||||
| 505 | |||||||||||
| 506 | =item say_pretty example 1 | ||||||||||
| 507 | |||||||||||
| 508 | package main; | ||||||||||
| 509 | |||||||||||
| 510 | my $example = Example->new(test => 123); | ||||||||||
| 511 | |||||||||||
| 512 | my $say_pretty = $example->say_pretty; | ||||||||||
| 513 | |||||||||||
| 514 | # bless({ test => 123 }, 'Example')\n | ||||||||||
| 515 | |||||||||||
| 516 | # 1 | ||||||||||
| 517 | |||||||||||
| 518 | =back | ||||||||||
| 519 | |||||||||||
| 520 | =over 4 | ||||||||||
| 521 | |||||||||||
| 522 | =item say_pretty example 2 | ||||||||||
| 523 | |||||||||||
| 524 | package main; | ||||||||||
| 525 | |||||||||||
| 526 | my $example = Example->new(test => 123); | ||||||||||
| 527 | |||||||||||
| 528 | my $say_pretty = $example->say_pretty; | ||||||||||
| 529 | |||||||||||
| 530 | # [ | ||||||||||
| 531 | # bless({ test => 123 }, 'Example'), | ||||||||||
| 532 | # 1, | ||||||||||
| 533 | # 2, | ||||||||||
| 534 | # 3 | ||||||||||
| 535 | # ]\n | ||||||||||
| 536 | |||||||||||
| 537 | # 1 | ||||||||||
| 538 | |||||||||||
| 539 | =back | ||||||||||
| 540 | |||||||||||
| 541 | =cut | ||||||||||
| 542 | |||||||||||
| 543 | =head2 say_string | ||||||||||
| 544 | |||||||||||
| 545 | say_string(string | coderef $method, any @args) (any) | ||||||||||
| 546 | |||||||||||
| 547 | The say_string method prints a string representation of the underlying data | ||||||||||
| 548 | without using a dump, with a trailing newline. This method supports | ||||||||||
| 549 | dispatching, i.e. providing a method name and arguments whose return value will | ||||||||||
| 550 | be acted on by this method. | ||||||||||
| 551 | |||||||||||
| 552 | I<Since C<0.09>> | ||||||||||
| 553 | |||||||||||
| 554 | =over 4 | ||||||||||
| 555 | |||||||||||
| 556 | =item say_string example 1 | ||||||||||
| 557 | |||||||||||
| 558 | package main; | ||||||||||
| 559 | |||||||||||
| 560 | my $example = Example->new(test => 123); | ||||||||||
| 561 | |||||||||||
| 562 | my $say_string = $example->say_string; | ||||||||||
| 563 | |||||||||||
| 564 | # "Example\n" | ||||||||||
| 565 | |||||||||||
| 566 | # 1 | ||||||||||
| 567 | |||||||||||
| 568 | =back | ||||||||||
| 569 | |||||||||||
| 570 | =cut | ||||||||||
| 571 | |||||||||||
| 572 | =head2 say_yaml | ||||||||||
| 573 | |||||||||||
| 574 | say_yaml(string | coderef $method, any @args) (any) | ||||||||||
| 575 | |||||||||||
| 576 | The say_yaml method prints a YAML representation of the underlying data. This | ||||||||||
| 577 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||
| 578 | return value will be acted on by this method, with a trailing newline. | ||||||||||
| 579 | |||||||||||
| 580 | I<Since C<2.91>> | ||||||||||
| 581 | |||||||||||
| 582 | =over 4 | ||||||||||
| 583 | |||||||||||
| 584 | =item say_yaml example 1 | ||||||||||
| 585 | |||||||||||
| 586 | package main; | ||||||||||
| 587 | |||||||||||
| 588 | my $example = Example->new(test => 123); | ||||||||||
| 589 | |||||||||||
| 590 | my $say_yaml = $example->say_yaml; | ||||||||||
| 591 | |||||||||||
| 592 | # "---\ntest: 123\n" | ||||||||||
| 593 | |||||||||||
| 594 | =back | ||||||||||
| 595 | |||||||||||
| 596 | =over 4 | ||||||||||
| 597 | |||||||||||
| 598 | =item say_yaml example 2 | ||||||||||
| 599 | |||||||||||
| 600 | package main; | ||||||||||
| 601 | |||||||||||
| 602 | my $example = Example->new(test => 123); | ||||||||||
| 603 | |||||||||||
| 604 | my $say_yaml = $example->say_yaml('execute'); | ||||||||||
| 605 | |||||||||||
| 606 | # "---\n- test: 123\n" | ||||||||||
| 607 | |||||||||||
| 608 | =back | ||||||||||
| 609 | |||||||||||
| 610 | =cut | ||||||||||
| 611 | |||||||||||
| 612 | =head1 AUTHORS | ||||||||||
| 613 | |||||||||||
| 614 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 615 | |||||||||||
| 616 | =cut | ||||||||||
| 617 | |||||||||||
| 618 | =head1 LICENSE | ||||||||||
| 619 | |||||||||||
| 620 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 621 | |||||||||||
| 622 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 623 | the terms of the Apache license version 2.0. | ||||||||||
| 624 | |||||||||||
| 625 | =cut | ||||||||||