Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

yosefm's scratchpad

by yosefm (Friar)
on Jun 03, 2004 at 05:35 UTC ( #359943=scratchpad: print w/replies, xml ) Need Help??

#! /usr/bin/perl use strict; package Context; my %versions = (); sub new { my $class = shift; return bless {}, $class; } sub declareVersion { my $self = shift; my ($plugin, $version) = @_; $versions{$plugin} = $version; } sub getVersion { shift; $versions{shift()} } sub addOpinion { my $self = shift; my ($plugin, $opinion) = @_; $self->{$plugin} = [] unless exists $self->{$plugin}; push @{$self->{$plugin}}, $opinion; } package main; sub usage; # General tool stuff use Getopt::Long; my @plugins; my $verbose; GetOptions('plugin=s' => \@plugins, 'verbose' => \$verbose); # Get input program. my $snippet = eval {local $/; return <>}; print $snippet if $verbose; # Load plugins @plugins = grep { eval{require "plugins/$"} ? 1 : (warn("Plug-in $_ failed to lo +ad.\n"), 0) } @plugins; # Start a new context; my $ctx = Context->new; # Initialization: foreach (@plugins) { $_->init($ctx) if UNIVERSAL::can($_, 'init'); } # Do the stuff foreach (@plugins) { $_->evaluate($ctx, $snippet); } # Simple output. while (my ($plugin, $opinions) = each %$ctx) { my $ver = undef; my $verstr = ($ver = Context->getVersion($plugin)) ? "(Version $ver) " : ''; print "The plugin $plugin ${verstr}says:\n"; print join '\n', map { "\t$_\n" } @$opinions; }


package grammar; sub init { my $pkg = shift; my $ctx = shift; $ctx->declareVersion($pkg, '0.1'); } sub evaluate { my $pkg = shift; my ($ctx, $snippet) = @_; if ($snippet =~ /use\s+strict;/) { $ctx->addOpinion($pkg, "Uses strict. OK"); } else { $ctx->addOpinion($pkg, "Does not use strict; Heathen swine!!"); } } 1;


package bench; use Benchmark; sub evaluate { my $pkg = shift; my ($ctx, $snippet) = @_; $ctx->addOpinion($pkg, timestr(timeit(400000, $snippet))); } 1;
Log In?

What's my password?
Create A New User
[1nickt]: Corion I assume you are talking about Retry? Attempt doesn;t offer callbacks and has a much simpler interface. (Also written by someone I trust...)
[perldigious]: I train for long portaging/rowing trips by carrying my kayak to the river about a half mile from my house 2-3 times a week depending on weather... but due to a lingering winter, I haven't had long to train this year.
[erix]: Ah, I found the link for my run: 6km (and 6km back)
[perldigious]: Also, made the unhappy discovery that the ticks have become active already this year... I really, really hate ticks.
[Lotus1]: perldigious I found out recently that opossums are very good at killing ticks.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2017-05-24 13:02 GMT
Find Nodes?
    Voting Booth?