Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Draft - Writng plugable programs with perl.

by yosefm (Friar)
on Jun 13, 2004 at 17:34 UTC ( [id://366279]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    ##################################
    # complain.pl  - find what's wrong with others' code fast!
    ...
    # Get input program.
    my $snippet = eval {local $/; return < >};
    print $snippet if $verbose;
    
  2. or download this
    foreach (@plugin_list) {
        require $_ or warn "Plugin $_ failed to load";
    }
    
  3. or download this
    # Load plugins
    @plugins = grep {
        eval{require "plugins/$_.pl"} ? 1 : (warn("Plug-in $_ failed to lo
    +ad.\n"), 0)
    } @plugins;
    
  4. or download this
    require Acme::Current;
    # or
    use Acme::Current;
    
  5. or download this
    use Module LIST;
    require EXPR;
    
  6. or download this
    foreach (@plugin_list) {
        $_->init;
    }
    
  7. or download this
    # Do the stuff
    foreach (@plugins) {
        $_->evaluate($snippet);
    }
    
  8. or download this
    # Initialization:
    foreach (@plugins) {
        $_->init if UNIVERSAL::can($_, 'init');
    }
    
  9. or download this
    #############################
    #  plugins/bench.pl
    ...
        print timestr(timeit(400000, $snippet)), "\n";
    }
    1;
    
  10. or download this
     $ ./complain.pl -p bench < snippet.txt
    
  11. or download this
    package Context;
    
    ...
        $self->{$plugin} = [] unless exists $self->{$plugin};
        push @{$self->{$plugin}}, $opinion;
    }
    
  12. or download this
    # Start a new context;
    my $ctx = Context->new;
    ...
    foreach (@plugins) {
        $_->evaluate($ctx, $snippet);
    }
    
  13. or download this
    sub evaluate {
        my $pkg = shift;
        my ($ctx, $snippet) = @_;
        $ctx->addOpinion($pkg, timestr(timeit(400000, $snippet)));
    }
    
  14. or download this
    
    # Simple output.
    ...
        print "The plugin $plugin ${verstr}says:\n";
        print join '\n', map { "\t$_\n" } @$opinions;
    }
    
  15. or download this
    ###############################
    #  plugins/grammar.pl
    ...
    }
    
    1;
    
  16. or download this
    perl -e'$b=unpack"b*",pack"H*","59dfce2d6b1664d3b26cd9969503";\
    for(;$a<length$b;$a+=9){print+pack"b8",substr$b,$a,8;}'
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://366279]
Approved by valdez
Front-paged by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found