in reply to Re: Replacing perl module with external program (is dumb)
in thread Replacing perl module with external program

Thank you for your helpful suggestion to this unworthy novice. Yes, I am dumb. I humbly apologise for not having yet attained enlightenment such as your Exalted Greatness has.

I have spent a day reading and rereading the TT2 documentation. It may as well be in Egyption Hieroglyphics. I have also gone into the source. I don't understand the source.

While my question uses a specific example, the question is a more general one. Here is a module that is used as a filter. A data stream comes into it, is modified, then returned to the program for further operations. Is there a general guide on how to replace such a filter, done by a module, with a module that uses an external program?

  • Comment on Re^2: Replacing perl module with external program (is dumb)

Replies are listed 'Best First'.
Re^3: Replacing perl module with external program (is dumb)
by MidLifeXis (Monsignor) on Jan 30, 2014 at 14:15 UTC

    In addition to AM's suggestion above, I would look at the possibility or need of supporting multiple versions. Perhaps replace the original module with a find-and-load module, and move the original one to Module::Name::VersionX, where VersionX is the support code for a single, standardized perl API.

    --MidLifeXis

Re^3: Replacing perl module with external program
by Anonymous Monk on Jan 29, 2014 at 23:25 UTC

    ... Is there a general guide on how to replace such a filter, done by a module, with a module that uses an external program?

    Its easy to create a new Template::Plugin::Filter, you simply copy/paste the existing Template::Plugin::MultiMarkdown, rename it (say Template::Plugin::MultiMarkdownBin ), and replace the module-calling-part with something that calls the external program.

    To know how to call this external program, the first step is locating the documentation for this external program to learn how to use it.

    Then use something as discussed in perlipc (open2,open3, qx ...

    You can use Capture::Tiny, IPC::Run3 ....

    But you start with the documentation of this external program...

      I can handle the external program. With suitable options it takes input from stdin, writes out to stdout and stderr.

      E.g. the following works:

      cat foo.md | multimarkdown | wc

      (But why would you want to count html kibbles?)

      If it helps, assume that I'm filtering through cut, or sort or sed or awk.

      WHICH external program is irrelevant to the discussion.

      Indeed, what I think I'm looking for is a generic pipe module that can be renamed and used with a single line edit, or that the command to be run is passed as a parameter.

      The part you breeze over is the part I'm having trouble with.

      Below is the content of Template/Plugin/MultiMarkdown.pm

      It in turn makes reference to Text::MultiMarkdown

      #$Id: MultiMarkdown.pm 4103 2009-03-02 20:41:50Z andrew $ package Template::Plugin::MultiMarkdown; use strict; use base qw (Template::Plugin::Filter); use Text::MultiMarkdown; our $VERSION = 0.03; sub init { my $self = shift; $self->{_DYNAMIC} = 1; $self->install_filter($self->{_ARGS}->[0] || 'multimarkdown'); return $self; } sub filter { my ($self, $text, $args, $config) = @_; my $m = Text::MultiMarkdown->new(%{$config || {}}); return $m->markdown($text); } <readmore> 1; __END__ =head1 NAME Template::Plugin::MultiMarkdown - TT plugin for Text::MultiMarkdown =head1 SYNOPSIS [% USE MultiMarkdown -%] [% FILTER multimarkdown %] #Foo Bar --- *Italic* blah blah **Bold** foo bar baz [%- END %] =head1 DESCRIPTION Template::Plugin::MultiMarkdown is a plugin for TT, which will format your text with MultiMarkdown Style. =head1 SUBROUTINES/METHODS There are two methods required by the TT plugin API: =over 4 =item C<init()> =item C<filter()> =back =head1 VERSION This man page describes version 0.03. =head1 SEE ALSO L<Template>, L<Text::MultiMarkdown>, L<http://fletcherpenney.net/multi +markdown/> =head1 AUTHOR Andrew Ford E<lt>A.Ford@ford-mason.co.ukE<gt> (based on the L<Template::Plugin::Markdown> TT plugin by Naoya Ito E<lt>naoya@bloghackers.netE<gt>). =head1 LICENSE AND COPYRIGHT Copyright (C) 2009 Andrew Ford This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut </readmore>

      So, I copy this to MultiMarkdownBin

      It no longer uses Text::Markdown so I can eliminate that.

      I need something from one of the 284 different IPC modules.

      Which one?

      WHAT do I replace in the above code?

      I am so far from enlightenment, that I'm waiting between photons.