Data::Tersify::Plugin - how to write a Data::Tersify plugin
package Data::Tersify::Plugin::Foo; sub handles { 'Foo' } sub tersify { my ($object) = @_; return q{They're all the same}; } package Data::Tersify::Plugin::ManyThings; sub handles { ['Bar', 'Bletch'] } sub tersify { my ($object) = @_; if (ref($object) eq 'Bar') { return 'ID ' . $object->id; } elsif (ref($object) eq 'Bletch') { return sprintf('UUID %s for %s', $object->uuid, $object->parent->id); } }
Any Data::Tersify plugin must (a) be in the Data::Tersify::Plugin namespace, and (b) implement the class methods handles and tersify.
Because Data::Tersify will not tersify an object via a plugin if it's the root structure passed to it, but will tersify an object if it's part of the internals of another object which isn't handled by a plugin, you should consider implementing your plugin by tersifying various components of an object, rather than the entire object. FIXME: why?
Out: @classes
This method returns one or more class names. These are classes that you're prepared to handle in your tersify method.
In: $object Out: $terse_description
Supplied with an object you have said in your handles that you know how to handle, this returns a scalar description of said object. Ideally descriptions should be short (40 characters or less), and provide only enough information needed to differentiate two similarly terse object descriptions.
Data::Tersify will mention the type of the object, and the refaddr, so you do not need to mention anything like this in your description.
To install Data::Tersify, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Tersify
CPAN shell
perl -MCPAN -e shell install Data::Tersify
For more information on module installation, please visit the detailed CPAN module installation guide.