| 1 | # | ||
| 2 | # Copyright (c) 2019 Christian Jaeger, copying@christianjaeger.ch | ||
| 3 | # | ||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||
| 7 | # bundled with this file. | ||
| 8 | # | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | FP::Abstract::Show - data constructor protocol | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | package FPShowExample::Foo { | ||
| 17 | 2 | ▶ | sub new { my $class = shift; bless [@_], $class } |
|
Subroutine
new: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | sub FP_Show_show { |
|
Subroutine
FP_Show_show: called CC=1 SCAR=0.0
| |||
| 19 | 2 | my ($self, $show) = @_; | |
| 20 | # $show is for recursive use | ||
| 21 | "FPShowExample::Foo->new(".join(", ", | ||
| 22 | 2 | map { $show->($_) } @$self).")" | |
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | 1 | ▶ | use FP::Show; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | |||
| 28 | is show(FPShowExample::Foo->new("hey", new FPShowExample::Foo 5+5)), | ||
| 29 | "FPShowExample::Foo->new('hey', FPShowExample::Foo->new(10))"; | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | For an introduction, see L<FP::Show>. | ||
| 34 | |||
| 35 | The reason that C<FP_Show_show> is getting a C<$show> argument is to | ||
| 36 | provide for (probably evil, though) context sensitive formatting, but | ||
| 37 | more importantly to hopefully enable to do pretty-printing and cut-off | ||
| 38 | features (this is *alpha* though, see whether this works out). | ||
| 39 | |||
| 40 | |||
| 41 | =head1 TODO | ||
| 42 | |||
| 43 | Handle circular data structures. | ||
| 44 | |||
| 45 | Pretty-printing -- for this, probably move to returning FP::AST::Perl | ||
| 46 | nodes instead of strings. | ||
| 47 | |||
| 48 | Declare that non-pretty-printing show must only print one line? | ||
| 49 | |||
| 50 | Cut-offs at configurable size | ||
| 51 | |||
| 52 | Configuration for whether to force promises | ||
| 53 | |||
| 54 | =head1 SEE ALSO | ||
| 55 | |||
| 56 | L<FP::Show> -- functions to access this protocol usefully | ||
| 57 | |||
| 58 | L<FP::Mixin::Utils> -- implemented by this protocol | ||
| 59 | |||
| 60 | =head1 NOTE | ||
| 61 | |||
| 62 | This is alpha software! Read the status section in the package README | ||
| 63 | or on the L<website|http://functional-perl.org/>. | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | package FP::Abstract::Show; | ||
| 68 | |||
| 69 | 61 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 70 | 61 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 71 | 61 | ▶ | use warnings FATAL => 'uninitialized'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 72 | |||
| 73 | 61 | ▶ | use base qw(FP::Mixin::Utils); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 74 | |||
| 75 | 267 | ▶ | sub FP_Interface__method_names { ("FP_Show_show") } |
|
Subroutine
FP_Interface__method_names: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 76 | |||
| 77 | 61 | 1 | |