App-SimpleScan-Plugin-Plaintext
view release on metacpan or search on metacpan
lib/App/SimpleScan/Plugin/Plaintext.pm view on Meta::CPAN
package App::SimpleScan::Plugin::Plaintext;
our $VERSION = '1.02';
use warnings;
use strict;
use Carp;
use base qw(Class::Accessor::Fast);
__PACKAGE__->mk_accessors( qw(plaintext) );
# Module implementation here
sub import {
no strict 'refs';
*{caller() . '::plaintext'} = \&plaintext;
}
sub pragmas {
return (['plaintext' => \&plaintext_pragma],
);
}
sub plaintext_pragma {
my($self, $args) = @_;
if( !defined $args or length($args) == 0) {
$self->stack_test( qq(fail "Missing argument for %%plaintext";\n) );
}
elsif ($args =~ /^(on|1)/i) {
$self->plaintext('1');
}
elsif ($args =~ /^(off|0)/i) {
$self->plaintext('0');
}
else {
$self->stack_test( qq(fail "Invalid argument for %%plaintext: $args";\n) );
}
}
sub filters {
return \&filter;
}
sub filter {
my ($self, @code) = @_;
if ($self->plaintext) {
@code = map { s/page_(.*?)like/text_${1}like/; $_ } @code;
}
return @code;
}
1; # Magic true value required at end of module
__END__
=head1 NAME
App::SimpleScan::Plugin::Plaintext - check a page's text without markup
=head1 VERSION
This document describes App::SimpleScan::Plugin::Plaintext version 1.00
=head1 SYNOPSIS
# Normal test specs use the entire HTML text
http://perl.org/ /books<\/a>\n \| / Y Sites list HTML
# If we want to match just the text, not the HTML:
%%plaintext on
http://perl.org/ /|books \| dev \| history \| jobs/ Y Literal list
# And we can turn this back off again:
%%plaintext off
( run in 1.874 second using v1.01-cache-2.11-cpan-5837b0d9d2c )