NAME
Data::Section::Pluggable::Role::ContentProcessorPlugin - Plugin role for Data::Section::Pluggable to process content
VERSION
version 0.03
SYNOPSIS
Instance mode:
use experimental qw( signatures );
use Data::Section::Pluggable;
package Data::Section::Pluggable::Plugin::MyPlugin {
use Role::Tiny::With;
use Class::Tiny qw( extensions );
with 'Data::Section::Pluggable::Role::ContentProcessorPlugin';
sub process_content ($self, $dsp, $content) {
$content =~ s/\s*\z//; # trim trailing whitespace
return "[$content]";
}
}
my $dsp = Data::Section::Pluggable->new
->add_plugin('my_plugin', extensions => ['txt']);
# prints '[Welcome to Perl]'
say $dsp->get_data_section('hello.txt');
__DATA__
@@ hello.txt
Welcome to Perl
Class mode:
use experimental qw( signatures );
use Data::Section::Pluggable;
package Data::Section::Pluggable::Plugin::MyPlugin {
use Role::Tiny::With;
with 'Data::Section::Pluggable::Role::ContentProcessorPlugin';
sub extensions ($class) {
return ('txt');
}
sub process_content ($class, $dsp, $content) {
$content =~ s/\s*\z//; # trim trailing whitespace
return "[$content]";
}
}
my $dsp = Data::Section::Pluggable->new
->add_plugin('my_plugin');
# prints '[Welcome to Perl]'
say $dsp->get_data_section('hello.txt');
__DATA__
@@ hello.txt
Welcome to Perl
DESCRIPTION
This plugin role provides a simple wrapper mechanism around the Data::Section::Pluggable method add_format, making it an appropriate way to add such recipes to CPAN.
CONSTRUCTOR
new
my $class->new(%args); # optional
If a constructor new
is provided, it will be called when the plugin is added to create an instance of the plugin. The methods below will be called as instance methods. Otherwise the methods will be called as class methods.
METHODS
All methods are to be implemented by your class.
extensions
my @extensions = $plugin->extensions;
my \@extensions = $plugin->extensions;
Returns a list or array reference of filename extensions the plugin should apply to.
process_content
my $processed = $plugin->process_content($dsp, $content);
Takes the Data::Section::Pluggable instance and content and returns the process content.
SEE ALSO
AUTHOR
Graham Ollis <plicease@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.