Changeset 7494


Ignore:
Timestamp:
08/23/09 23:27:21 (2 years ago)
Author:
azawawi
Message:

[Padre/tools] parse_perlopref.pl is using github permanent links (Ryan52++, garu++)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/parse_perlopref.pl

    r7328 r7494  
    22use warnings; 
    33 
    4 # 
    5 # Parse an online perlopref.pod and returns a hash of topics and help 
    6 # 
    7 sub parse_perlopref { 
    8     my $url = shift; 
    9      
    10     print "Loading $url\n"; 
    11     require LWP::UserAgent; 
    12     require HTTP::Request; 
    13     my $ua = LWP::UserAgent->new; 
    14     my $req = HTTP::Request->new(GET => $url); 
    15     my $res = $ua->request($req); 
    16     if(not $res->is_success) { 
    17         die $res->status_line, "\n"; 
    18     } 
    19  
    20     # Open perlopref 
    21     my $fh; 
    22     my $content = $res->content; 
    23     open $fh, "<", \$content; 
    24  
    25  
    26     my %index = (); 
    27  
    28     # Add PRECEDENCE to index 
    29     until (<$fh> =~ /=head1 PRECEDENCE/) { } 
    30  
    31     my $line; 
    32     while($line = <$fh>) { 
    33         last if($line =~ /=head1 OPERATORS/); 
    34         $index{PRECEDENCE} .= $line; 
    35     } 
    36  
    37     # Add OPERATORS to index 
    38     my $op; 
    39     while($line = <$fh>) { 
    40         if($line =~ /=head2\s+(.+)$/) { 
    41             $op = $1; 
    42         } elsif($op){ 
    43             $index{$op} .= $line; 
    44         } 
    45     } 
    46  
    47     # and we're done 
    48     close $fh; 
    49  
    50     return %index; 
     4my $url = 'http://github.com/cowens/perlopref/raw/master/perlopref.pod'; 
     5print "Loading $url\n"; 
     6require LWP::UserAgent; 
     7require HTTP::Request; 
     8my $ua = LWP::UserAgent->new; 
     9my $req = HTTP::Request->new(GET => $url); 
     10my $res = $ua->request($req); 
     11if(not $res->is_success) { 
     12    die $res->status_line, "\n"; 
    5113} 
    5214 
    53 my %op_ref = parse_perlopref 'http://github.com/cowens/perlopref/raw/456675100b4e4b7fb048e7fa2b525bcf7145070c/perlopref.pod'; 
    54 print "Indexed " . (scalar keys %op_ref) . " topic\n"; 
     15print $res->content; 
    5516 
    5617__END__ 
     
    5819=head1 NAME 
    5920 
    60 parse_perlopref.pl - A script to parse perlopref 
     21update_perlopref.pl - A script to download the latest copy of perlopref.pod from github 
    6122 
    6223=head1 DESCRIPTION 
    6324 
    64 This is a simple script to load perlopref.pod from github and generate an index 
    65 which we can re-use in Padre Help Search. 
     25This is a simple script to load perlopref.pod from github and write it in its  
     26proper Padre folder 
    6627 
    6728=head1 AUTHOR 
Note: See TracChangeset for help on using the changeset viewer.