Tersify/Plugin.pm

filter: Statementstmt 100% 1 / 1 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 1 / 1 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Tersify/perldb.pm ↑ Summary Tersify/Summary.pm »
1 package Data::Tersify::Plugin;
2  
3 =head1 NAME
4  
5 Data::Tersify::Plugin - how to write a Data::Tersify plugin
6  
7 =head1 SYNOPSIS
8  
9 package Data::Tersify::Plugin::Foo;
10
11 sub handles { 'Foo' }
12 sub tersify {
13 my ($object) = @_;
14 return q{They're all the same};
15 }
16  
17 package Data::Tersify::Plugin::ManyThings;
18
19 sub handles { ['Bar', 'Bletch'] }
20 sub tersify {
21 my ($object) = @_;
22 if (ref($object) eq 'Bar') {
23 return 'ID ' . $object->id;
24 } elsif (ref($object) eq 'Bletch') {
25 return sprintf('UUID %s for %s',
26 $object->uuid, $object->parent->id);
27 }
28 }
29  
30 =head1 DESCRIPTION
31  
32 Any Data::Tersify plugin must (a) be in the Data::Tersify::Plugin namespace,
33 and (b) implement the class methods L<handles> and L<tersify>.
34  
35 Because Data::Tersify will not tersify an object via a plugin if it's the root
36 structure passed to it, but I<will> tersify an object if it's part of the
37 internals of another data structure, or an object which isn't handled by a
38 plugin, you should consider implementing your plugin by tersifying I<various
39 components> of an object, rather than the entire object.
40  
41 That way, you'll get identical results if you get passed (a) an object directly
42 (Data::Tersify preserves the top-level elements, but will let you tersify
43 any sub-elements), or (b) an object as part of a data structure or another
44 object (Data::Tersify will offer to let you tersify the object as a whole).
45  
46 =head2 handles
47  
48 Out: @classes
49  
50 This method returns one or more class names. These are classes that you're
51 prepared to handle in your L<tersify> method.
52  
53 =head2 handles_subclasses
54  
55 Out: $handles_subclasses
56  
57 Optional. Return a true value from this method if you're I<also> prepared to
58 tersify subclasses of any of your handled classes.
59  
60 =head2 tersify
61  
62 In: $object
63 Out: $terse_description
64  
65 Supplied with an object you have said in your L<handles> that you know how
66 to handle, this returns a scalar description of said object. Ideally
67 descriptions should be short (40 characters or less), and provide only
68 enough information needed to differentiate two similarly terse object
69 descriptions.
70  
71 Data::Tersify will mention the type of the object, and the refaddr, so
72 you do not need to mention anything like this in your description.
73  
74 =cut
75  
76 1 1;
« Tersify/perldb.pm ↑ Summary Tersify/Summary.pm »