App-SimpleScan
view release on metacpan or search on metacpan
The interfaces to this module are still evolving; plugin developers
should monitor CPAN and look for new versions of this module.
Henceforth, any change to the externals of this module will be denoted
by a full version increase (e.g., from 0.34 to 1.00).
INTERFACE
Class methods
new
Creates a new instance of the application. Also invokes all of the basic
setup so that when "go" is called, all of the plugins are available and
all callbacks are in place.
Instance methods
Execution methods
go
Executes the application. Calls the subsidiary methods to read input,
parse it, do substitutions, and transform it into code; loads the
plugins and any code filters which they wish to install.
After the code is created, it consults the command-line switches and
runs the generated program, prints it, or both.
input) as a string of text. It is up to the pragma to parse the string;
the use of "expand_backticked" is recommended for pragmas which take a
variable number of arguments, and wish to adhere to the same syntax that
standard substitutions use.
PLUGIN SUMMARY
Standard plugin methods that App::SimpleScan will look for; none of
these is required, though you should choose to implement the ones that
you actually need.
Basic callbacks
init
The "init" class method is called by "App:SimpleScan" when the plugin
class is loaded; the "App::SimpleScan" object is suppled to allow the
plugin to alter or add to the contents of the object. This allows
plugins to export methods to the base class, or to add instance
variables dynamically.
Note that the class passed in to this method is the class of the
*plugin*, not of the caller ("App::SimpleScan" or a derived class). You
should use caller() if you wish to export subroutines into the package
lib/App/SimpleScan.pm view on Meta::CPAN
use WWW::Mechanize::Pluggable;
use Test::WWW::Simple;
use App::SimpleScan::TestSpec;
use App::SimpleScan::Substitution;
use Graph;
use Module::Pluggable search_path => [qw(App::SimpleScan::Plugin)];
use base qw(Class::Accessor);
__PACKAGE__->mk_accessors(qw(sub_engine tests test_count
next_line_callbacks _deps));
$|++; ##no critic
use App::SimpleScan::TestSpec;
my $reference_mech = WWW::Mechanize::Pluggable->new;
my $sub_engine = App::SimpleScan::Substitution->new;
my @local_pragma_support =
(
lib/App/SimpleScan.pm view on Meta::CPAN
# another angle-bracketed item ...
# if there are any ...
# and a close angle-bracket
my $in_or_out_bracketed = qr/ ($out_angled) | ($in_angled) /x;
################################
# Basic class methods.
# Create the object.
# - load and install plugins
# - make object available to test specs for callbacks
# - clear the tests and test count
# - process the command-line options
# - return the object
sub new {
my ($class) = @_;
my $self = {};
bless $self, $class;
$self->_deps(Graph->new);
$self->sub_engine($sub_engine);
# initialize fields first; plugins may expect good values.
$self->next_line_callbacks([]);
$self->tests([]);
$self->test_count(0);
$self->{InputQueue} = [];
# Load and install the plugins.
$self->_load_plugins();
$self->install_pragma_plugins;
# TestSpec needs to be able to find the App object.
App::SimpleScan::TestSpec->app($self);
lib/App/SimpleScan.pm view on Meta::CPAN
##########################
# Input queueing
# Handle input queueing. If there's anything queued,
# return it first; otherwise, just read another line
# from the magic input filehandle.
sub next_line {
my ($self) = shift;
my $next_line;
# Call and plugin-installed input callbacks.
# These can do whatever they like to the line stack, the
# object, etc.
foreach my $callback (@ {$self->next_line_callbacks() }) {
$callback->($self);
}
# If we have lines on the input queue, read from there.
if (defined $self->{InputQueue}->[0] ) {
$next_line = shift @{ $self->{InputQueue} };
}
# Else we read lines from the standard input.
else {
lib/App/SimpleScan.pm view on Meta::CPAN
0.34 to 1.00).
=head1 INTERFACE
=head2 Class methods
=head2 new
Creates a new instance of the application. Also invokes
all of the basic setup so that when C<go> is called, all
of the plugins are available and all callbacks are in place.
=head2 Instance methods
=head3 Execution methods
=head4 go
Executes the application. Calls the subsidiary methods to
read input, parse it, do substitutions, and transform it into
code; loads the plugins and any code filters which they wish to
lib/App/SimpleScan.pm view on Meta::CPAN
C<expand_backticked> is recommended for pragmas which
take a variable number of arguments, and wish to adhere
to the same syntax that standard substitutions use.
=head1 PLUGIN SUMMARY
Standard plugin methods that App::SimpleScan will look for;
none of these is required, though you should choose to
implement the ones that you actually need.
=head2 Basic callbacks
=head3 init
The C<init> class method is called by C<App:SimpleScan>
when the plugin class is loaded; the C<App::SimpleScan>
object is suppled to allow the plugin to alter or add to the
contents of the object. This allows plugins to export methods
to the base class, or to add instance variables dynamically.
Note that the class passed in to this method is the class
t/40inputq.t view on Meta::CPAN
use_ok qw(App::SimpleScan);
use_ok qw(App::SimpleScan::TestSpec);
push @INC, "t";
}
my $ss = new App::SimpleScan;
ok $ss->can('plugins'), "plugins method available";
isa_ok [$ss->plugins()],"ARRAY", "plugin list";
is 1, ( grep { /TestNextLine/ } $ss->plugins() ), "test plugin there";
ok scalar @{ $ss->next_line_callbacks }, "plugin installed callback";
$ENV{HARNESS_PERL_SWITCHES} = "" unless defined $ENV{HARNESS_PERL_SWITCHES};
@output = `$^X $ENV{HARNESS_PERL_SWITCHES} -Mlib='t' -Iblib/lib bin/simple_scan -gen -test_nextline <examples/ss_escaped.in 2>&1`;
@expected = map {"$_\n"} split /\n/,<<EOF;
use Test::More tests=>1;
use Test::WWW::Simple;
use strict;
use Test::Demo;
t/App/SimpleScan/Plugin/TestNextLine.pm view on Meta::CPAN
my($test_nextline);
sub import {
no strict 'refs';
*{caller() . '::test_nextline'} = \&test_nextline;
}
sub init {
my ($class, $app) = @_;
no strict 'refs';
my $callbacks_ref = $app->next_line_callbacks();
push @{ $callbacks_ref }, \&demo_callback;
$app->next_line_callbacks($callbacks_ref);
$app->{demo_called} = 0;
}
sub test_nextline {
my ($self, $value) = @_;
$test_nextline = $value if defined $value;
$test_nextline;
}
sub options {
t/App/SimpleScan/Plugin/TestNextLine.pm view on Meta::CPAN
my $n = $app->{demo_called} += 1;
my $s = ($n == 1) ? '' : 's';
$app->stack_code( qq(# next line plugin called $n time$s\n) );
}
1; # Magic true value required at end of module
__END__
=head1 NAME
App::SimpleScan::Plugin::TestNextLine - Dummy plugin to test next_line callbacks
=head1 SYNOPSIS
use App::SimpleScan;
my $app = new App::SimpleScan;
$app->go; # plugin loaded automatically here
=head1 DESCRIPTION
( run in 0.322 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )