PadrePluginPDL: Help.diff

File Help.diff, 3.2 KB (added by run4flat, 2 years ago)

Revised patch.

  • lib/Padre/Plugin/PDL/Help.pm

    old new  
    3131        } 
    3232 
    3333        if ( defined $pdldoc ) { 
    34             $self->{pdl_help} = $pdldoc->gethash; 
    35  
    36             # Delete those cool PDL modules that 
    37             # Perl 5 Help search will include 
    38             for my $k ( keys %{ $self->{pdl_help} } ) { 
    39                 if ( $k =~ /^PDL::/ ) { 
    40                     delete $self->{pdl_help}->{$k}; 
    41                 } 
    42             } 
     34            # Store in self for later access: 
     35            $self->{pdl_help} = $pdldoc; 
    4336        } 
    4437    }; 
    4538    if ($@) { 
     
    6154 
    6255    my ( $html, $location ); 
    6356    my $pdl_help = $self->{pdl_help}; 
    64     if ( defined $pdl_help && exists $pdl_help->{$topic} ) { 
    65         $html = ''; 
    66         my $help         = $pdl_help->{$topic}; 
    67         my %SECTION_NAME = ( 
    68             Module  => 'Module', 
    69             Ref     => 'Reference', 
    70             Sig     => 'Signature', 
    71             Bad     => 'Bad values', 
    72             Usage   => 'Usage', 
    73             Example => 'Example', 
    74         ); 
    75         foreach my $section (qw(Module Ref Sig Bad Usage Example)) { 
    76             if ( defined $help->{$section} ) { 
    77                 my $help = $help->{$section}; 
    78                 my $name = $SECTION_NAME{$section}; 
    79                 if (   $section eq 'Example' 
    80                     or $section eq 'Sig' 
    81                     or $section eq 'Usage' ) 
    82                 { 
    83                     $html .= "<p><b>$name</b><pre>" . $help . "</pre></p>"; 
    84                 } elsif ( $section eq 'Module' ) { 
    85                     $html .= qq{<p><b><a href="perldoc:$help">$help</a></b></p>}; 
    86                 } else { 
    87                     $html .= "<p><b>$name</b><br>" . $help . "</p>"; 
    88                 } 
    89             } 
     57    if ( defined $pdl_help && exists $pdl_help->gethash->{$topic} ) { 
     58        require Padre::Pod2HTML; 
     59         
     60        # We have two possibilities: the $topic can either be a module, or it 
     61        # can be a function. If the latter, we extract its pod from the database. 
     62        # If the former, just pull the pod from the file. We distinguish between 
     63        # them by noting that functions have a Module key, whereas modules  
     64        # (ironically) don't. 
     65        if (exists $pdl_help->gethash->{$topic}->{Module}) { 
     66            # Get the pod docs from the docs database: 
     67            my $pod_handler = StrHandle->new; # defined in PDL::Doc 
     68            $pdl_help->funcdocs($topic, $pod_handler); 
     69             
     70            # Convert them to HTML 
     71            $html = Padre::Pod2HTML->pod2html($pod_handler->text); 
     72             
     73            # Replace the filename in the "docs from" section with the module name: 
     74            my $module_name = $pdl_help->gethash->{$topic}{Module}; 
     75            $html =~ s{Docs from .*\.pm} 
     76                {Docs from <a href="perldoc:$module_name">$module_name<\/a>}; 
    9077        } 
    91  
     78        else { 
     79            $html = Padre::Pod2HTML->file2html($pdl_help->gethash->{$topic}->{File}); 
     80        } 
     81         
    9282        $location = $topic; 
    9383    } else { 
    9484        ( $html, $location ) = $self->{p5_help}->help_render($topic); 
     
    10494    my $self = shift; 
    10595 
    10696    # Return a unique sorted index 
    107     my @index = keys %{ $self->{pdl_help} }; 
     97    my @index = keys %{ $self->{pdl_help}->gethash }; 
    10898 
    10999    # Add Perl 5 help index to PDL 
    110     foreach my $topic ( @{ $self->{p5_help}->help_list } ) { 
    111         push @index, $topic; 
    112     } 
     100    #foreach my $topic ( @{ $self->{p5_help}->help_list } ) { 
     101    #   push @index, $topic; 
     102    #} 
     103    # I think this is a faster way of doing the above: 
     104    push @index, @{ $self->{p5_help}->help_list }; 
    113105 
     106    # Make sure things are only listed once: 
    114107    my %seen = (); 
    115108    my @unique_sorted_index = sort grep { !$seen{$_}++ } @index; 
    116109    return \@unique_sorted_index;