PDL/Help.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 79 CC 4 SCAR 15.9
CC
4
Cov
0%
help_render
12.0
help_init
6.0
help_list
2.0
CRAP 4.9
1 package Padre::Plugin::PDL::Help;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6  
7 # For Perl 6 documentation support
8 use Padre::Help ();
9  
10 our $VERSION = '0.05';
11  
12 our @ISA = 'Padre::Help';
13  
14 #
15 # Initialize help
16 #
17 sub help_init {
18 my $self = shift;
19  
20 # Workaround to get Perl + PDL help. Also, we'll need this so we can clean
21 # out things from the PDL help list that are already covered by Perl's
22 # normal help facilities.
23 require Padre::Document::Perl::Help;
24 $self->{p5_help} = Padre::Document::Perl::Help->new;
25 $self->{p5_help}->help_init;
26  
27 require Padre::Plugin::PDL::Util;
28 my $pdldoc = Padre::Plugin::PDL::Util::get_pdldoc();
29 if ( defined $pdldoc ) {
30 $self->{pdldoc} = $pdldoc;
31 $self->{pdldoc_hash} = $pdldoc->gethash;
32 }
33 }
34  
35 #
36 # Renders the help topic content
37 #
38 sub help_render {
39 my $self = shift;
40 my $topic = shift;
41  
42 my ( $html, $location );
43 my $pdldoc_hash = $self->{pdldoc_hash};
44 if ( defined $pdldoc_hash && exists $pdldoc_hash->{$topic} ) {
45 require Padre::Pod2HTML;
46  
47 # We have two possibilities: the $topic can either be a module,
48 # or it can be a function. If the latter, we extract its pod
49 # from the database.
50 # If the former, just pull the pod from the file. We distinguish
51 # between them by noting that functions have a Module key,
52 # whereas modules (ironically) don't.
53 if ( exists $pdldoc_hash->{$topic}->{Module} ) {
54  
55 # Get the pod docs from the docs database:
56 my $pod_handler = StrHandle->new; # defined in PDL::Doc
57 $self->{pdldoc}->funcdocs( $topic, $pod_handler );
58  
59 # Convert them to HTML
60 $html = Padre::Pod2HTML->pod2html( $pod_handler->text );
61  
62 # Replace the filename in the "docs from" section with
63 # the module name
64 my $module_name = $pdldoc_hash->{$topic}{Module};
65 $html =~ s{Docs from .*\.pm}
66 {Docs from <a href="perldoc:$module_name">$module_name<\/a>};
67 } else {
68 $html = Padre::Pod2HTML->file2html( $pdldoc_hash->{$topic}->{File} );
69 }
70  
71 $location = $topic;
72 } else {
73 ( $html, $location ) = $self->{p5_help}->help_render($topic);
74 }
75  
76 return ( $html, $location );
77 }
78  
79 #
80 # Returns the help topic list
81 #
82 sub help_list {
83 my $self = shift;
84  
85 # Return a unique sorted index
86 my @index = keys %{ $self->{pdldoc_hash} };
87  
88 # Add Perl 5 help index to PDL
89 push @index, @{ $self->{p5_help}->help_list };
90  
91 # Make sure things are only listed once:
92 my %seen = ();
93 my @unique_sorted_index = sort grep { !$seen{$_}++ } @index;
94 return \@unique_sorted_index;
95 }
96  
97 1;
98  
99 __END__