Data::Section::Pluggable::Role::ContentProcessorPlugin - Plugin role for Data::Section::Pluggable to process content
version 0.08
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
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.
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.
All methods are to be implemented by your class.
my @extensions = $plugin->extensions; my \@extensions = $plugin->extensions;
Returns a list or array reference of filename extensions the plugin should apply to.
my $processed = $plugin->process_content($dsp, $content);
Takes the Data::Section::Pluggable instance and content and returns the process content.
Graham Ollis <plicease@cpan.org>
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.