I needed a way to get the current perl version's embed.fnc file so I wrote thie function to fetch and cache the file from the search.cpan.org web site. You'd provide your own filename to fetch.

print cached_current_perl_source_file( 'embed.fnc' )
use strict; use warnings; use List::Util 'first'; use Config; use Cache::FileCache; sub cached_current_perl_source_file { my $filename = shift; my $cache = Cache::FileCache->new( { namespace => 'perl-source' } +); my $contents = $cache->get( "$Config{'version'}/$filename" ); if ( not defined $contents ) { $contents = current_perl_source_file( $filename ); $cache->set( "$Config{'version'}/$filename" => $contents, "nev +er" ); } $contents; } sub current_perl_source_file { my $filename = shift; require WWW::Mechanize; my $w = current_perl_source(); $w->follow_link( text => $filename ); $w->content; } sub current_perl_source { my $w = current_perl_page(); require WWW::Mechanize; $w->follow_link( text_regex => qr/Browse/ ); $w; } sub WWW::Mechanize::to_text { require HTML::FormatText; HTML::FormatText->new->format_string( $_[0]->content ); } sub find_url_option { require Carp; defined $_[0] or Carp::confess "Undefined form"; $_[0]->find_input( qw[ url option ] ); } sub current_perl_page { my $w = latest_perl_page(); my $form_number = other_releases_form( $w ) ; my $value_name = do { my $form = ( $w->forms )[ $form_number - 1 ]; my $o = find_url_option( $form ); my %values; @values{$o->value_names} = $o->possible_values; $values{ List::Util::first { /$Config{'version'}/o } keys %values } }; $w->form_number( $form_number ); $w->set_visible( [ option => $value_name ] ); $w->click; $w; } sub other_releases_form { my $w = shift; my @forms = $w->forms; for my $form_ix ( 0 .. $#forms ) { if ( find_url_option( $forms[$form_ix] ) ) { return 1 + $form_ix; } } die "Couldn't find Other Releases on " . $w->url; } sub latest_perl_page { require WWW::Mechanize; my $w = WWW::Mechanize->new; $w->get( 'http://search.cpan.org' ); $w->set_visible( "perl", [ qw[ option dist ] ] ); $w->submit_form; # Page through CPAN's search results until I hit the end or find t +he right # page. while ( 1 ) { $w->follow_link( text_regex => qr/^perl-\d+/ ) and return $w; $w->follow_link( text_regex => qr/^Next /i ) or die "Couldn't find perl on http://search.cpan.org"; } }

In reply to Fetch perl source code for your current interpreter by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.