Fetching contributors…
Cannot retrieve contributors at this time
60 lines (47 sloc) 1.4 KB
# Copyright (c) 2015 Christian Jaeger,
# This is free software, offered under either the same terms as perl 5
# or the terms of the Artistic License version 2 or the terms of the
# MIT License (Expat version). See the file that came
# bundled with this file.
=head1 NAME
package Foo;
use FP::Struct ["a","b"],
use FP::Show;
show (Foo->new(1,2)) # => "Foo(1,2)"
This class simply provides an `FP_Show_show` method that uses
inspection specific to FP::Struct classes to get to know the public
field values of the object it is being called on, and reconstructs a
constructor call based on this information. Meaning, for the typical
`FP::Struct` based class, it will do the right thing.
package FP::Show::Base::FP_Struct;
use strict; use warnings; use warnings FATAL => 'uninitialized';
sub FP_Show_show {
my ($self,$show)=@_;
my $class= ref ($self);
length $class
or die "FP_Show_show called on non-object: $self";
my $fieldnames= do {
no strict 'refs';
my @class_parts= split /::/, $class;
join(", ",
map {
my $fieldname= FP::Struct::field_name($_);
} FP::Struct::all_fields([$class])).