App::SimpleScan::Plugin::Plaintext - check a page's text without markup


App-SimpleScan-Plugin-Plaintext documentation Contained in the App-SimpleScan-Plugin-Plaintext distribution.

Index


Code Index:

NAME

Top

App::SimpleScan::Plugin::Plaintext - check a page's text without markup

VERSION

Top

This document describes App::SimpleScan::Plugin::Plaintext version 1.00

SYNOPSIS

Top

    # 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

DESCRIPTION

Top

This plugin adds the %%plaintext pragma. This allows you to write test specs that match the visible text on a page, as opposed to the HTML text. This is useful if you want to make sure (for instance) if specific text is on the page, but you don't care how it's marked up.

INTERFACE

Top

pragmas

Exports the %%plaintext pragma handler to App::SimpleScan.

plaintext_pragma

Actually handles the pragma statement. Calls the exported plaintext method to record the current state (on or off).

filters

Standard App::SimpleScan callback; returns the code filters.

filter

If the plaintext method returns true, we alter the tests to use text_like and text_unlike instead of page_like and page_unlike. In eitehr case, we return the code to the caller (standard interface).

DIAGNOSTICS

Top

Invalid argument for %%plaintext: %s

You supplied an argument other than '1' or 'on' to turn plaintext processing on, or '0' or 'off' to turn it off.

CONFIGURATION AND ENVIRONMENT

Top

App::SimpleScan::Plugin::Plaintext requires no configuration files or environment variables.

DEPENDENCIES

Top

App::SimpleScan, Class:Accessot::Fast.

INCOMPATIBILITIES

Top

None reported.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests to bug-app-simplescan-plugin-plaintext@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Top

Joe McMahon <mcmahon@cpan.org>

LICENCE AND COPYRIGHT

Top

DISCLAIMER OF WARRANTY

Top

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


App-SimpleScan-Plugin-Plaintext documentation Contained in the App-SimpleScan-Plugin-Plaintext distribution.

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__