Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

RFC: Pod::Remove

by domm (Chaplain)
on Mar 13, 2003 at 11:09 UTC ( [id://242648]=perlmeditation: print w/replies, xml ) Need Help??

Some comments I'd request very much:
  • Namespace
  • If it is possible to get Pod::Stripper to return a string (without heavy hacking like tied filehandles eet al), thus making this proposed module rather useless.

You can download the module from here

From the POD

NAME

Pod::Remove - Remove POD from code


SYNOPSIS

  use Pod::Remove qw(remove_pod);

  # $code is a string containing Perl-code with POD
  my $podless=remove_pod($code);

  # or, without importing:
  use Pod::Remove;

  my $podless=Pod::Remove::remove_pod($code);


DESCRIPTION

Pod::Remove removes POD from Perl Code. It accomplishes this by scanning each line of input and removing everything between /^=/ and /^=cut/. Everything after __END__ and __DATA__ is also removed.

Rather simple, but effective.

There is another module doing something similar, Pod::Stripper. Pod::Stripper is based on Pod::Parser, which works mainly on input- and output-streams, i.e. files or filehandles. Which makes it really hard to capture the result in a string. Which is the reason I wrote Pod::Remove.

I might implement some functions to make handling of various types of input easier. But not now.

-- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Replies are listed 'Best First'.
Re: RFC: Pod::Remove
by IlyaM (Parson) on Mar 13, 2003 at 11:34 UTC
    Pod::Stripper is based on Pod::Parser, which works mainly on input- and output-streams, i.e. files or filehandles. Which makes it really hard to capture the result in a string.

    In Perl >= 5.8.0 it is not a problem:

    # opens filehandle to "in memory" files held in Perl scalars open($fh,'>', \$variable);

    In Perl < 5.8.0 you can use IO::Scalar to do the same thing.

    Another comment: why not patch existing module to do what you want instead of creating yet another CPAN module?

    --
    Ilya Martynov, ilya@iponweb.net
    CTO IPonWEB (UK) Ltd
    Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
    Personal website - http://martynov.org

      Firstly, thanks for the feedback.

      Secondly: I'm (still) using 5.6.1 and did't know of the feature you mentioned. Using IO::Scalar might also be feasable.

      Another comment: why not patch existing module to do what you want instead of creating yet another CPAN module?

      Pod::Parser seems rather complex, so I thought patching it to return a scalar instead of writing to a FILEHANDLE would be hard. Passing an IO::Scalar-FH (or adding some methods to Pod::Parser that implement this) might be a good idea.

      On the other hand, Pod::Parser seems like a little bit of overkill, if all I want to do is remove POD.

      I'll give it a thought, and talk to Marek Rouchal about patching Pod::Parser.

      UPDATE

      Marek suggested using Pod::Simple, as "therein lies the future" (his words). So I'll take a look there...

      -- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
Re: RFC: Pod::Remove
by Abigail-II (Bishop) on Mar 13, 2003 at 22:42 UTC
    I've at least two modules on CPAN that will break if you remove everything after __DATA__. Note also that all modules that use AutoLoader or SelfLoader will have the bulk of their code after a __DATA__ or __END__ token.

    Furthermore, there's no POD in the following code:

    print "Hello, =pod world =cut ";

    Although your stripper would remove three lines from the code.

    Abigail

      I've at least two modules on CPAN that will break if you remove everything after __DATA__. Note also that all modules that use AutoLoader or SelfLoader will have the bulk of their code after a __DATA__ or __END__ token.

      Good point. So I'll leave __DATA__ and __END__ as is.

      Furthermore, there's no POD in the following code:

      print "Hello, =pod world =cut ";
      Although your stripper would remove three lines from the code.

      Another good point. I'm currently trying to get on the pod-people mailing list, but the subscriber adress seems to be broken..

      Anyway, thanks for the feedback, I'll try to get Pod::Simple to DWIM.

      -- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
Re: RFC: Pod::Remove
by dakkar (Hermit) on Mar 13, 2003 at 13:46 UTC

    I can understand the feeling that Pod::Parser is overkill, but:

    • Why strings?
    • What about DATA filehandles?

    -- 
            dakkar - Mobilis in mobile
    
      * Why strings?

      Because for some reasons having to do with cpanstats I want to analyse the code of some CPAN modules. I'm not interested in the POD, so I want to remove it. And I do not want to mess around with files (especially when running some analysis on all of CPAN) just to remove POD.

      What I want is something like

      my $podless=remove_pod($code)
      so I can mung $podless.

      * What about DATA filehandles?

      I'm not sure what you mean by this..

      -- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

        What I meant is: since you are removing everything after __DATA__, if the program had something besides POD in there, and accessed it via the DATA filehandle, it would no longer work.

        Reading your reply, anyway, I'm starting to believe you are not going to run those script.

        -- 
                dakkar - Mobilis in mobile
        
Re: RFC: Pod::Remove
by perlino (Initiate) on Jul 21, 2015 at 13:42 UTC

    ...patching it to return a scalar instead of writing to a FILEHANDLE would be hard...

    I had a look at Pod::Parser and found how to do it easily.

    You just pass two filehandles instead of one, like this:

    my $stripper = new Pod::Stripper(); my $stripped; open my $fh, '<', 'pod.pl'; open my $stripped_fh, '>', \$stripped; $stripper->parse_from_filehandle( $fh, $stripped_fh ); close $stripped_fh; close $fh; print $stripped;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-26 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found