PDL/Util.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 62 CC 8 SCAR 24.4
CC
8
Cov
0%
get_pdldoc
20.0
add_pdl_keywords_highlighting
12.0
get_pdl_keywords
12.0
CRAP 11.4
1 package Padre::Plugin::PDL::Util;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6  
7 our $VERSION = '0.05';
8  
9 # Cached items
10 my $pdl_keywords;
11 my $pdldoc;
12  
13 # Adds awesome PDL keywords highlighting
14 # Not the smartest though at the moment :)
15 sub add_pdl_keywords_highlighting {
16 my $document = shift;
17 my $editor = shift;
18  
19 my $keywords = Padre::Wx::Scintilla->keywords($document);
20 if ( Params::Util::_ARRAY($keywords) ) {
21 foreach my $i ( 0 .. $#$keywords ) {
22 my $keyword_list = $keywords->[$i];
23 if ( $i == 0 ) {
24 $keyword_list .= ' ' . get_pdl_keywords();
25 }
26 $editor->Wx::Scintilla::TextCtrl::SetKeyWords( $i, $keyword_list );
27 }
28 }
29  
30 return;
31 }
32  
33 # Gets a space-seperated PDL keyword list that is used Scintilla's SetKeyWords
34 sub get_pdl_keywords {
35  
36 # Returned cached PDL keywords if it is already defined
37 return $pdl_keywords if defined $pdl_keywords;
38  
39 # Find the pdl documentation
40 my $pdldoc = get_pdldoc();
41  
42 # Cache the space seperated keyword list
43 $pdl_keywords = defined $pdldoc ? join ' ', keys %{ $pdldoc->gethash } : '';
44  
45 # And return it
46 return $pdl_keywords;
47 }
48  
49 # Returns the cached pdldoc is found
50 # Otherwise tries to create one
51 sub get_pdldoc {
52  
53 # Returned cached PDL keywords if it is there
54 return $pdldoc if defined $pdldoc;
55  
56  
57 # Find PDL documentation and return the pdl object
58 require PDL::Doc;
59 for my $dir (@INC) {
60 my $file = "$dir/PDL/pdldoc.db";
61 if ( -f $file ) {
62 $pdldoc = new PDL::Doc($file);
63 last;
64 }
65 }
66  
67 # A simple warn. I wish padre had a better logging facility
68 warn "PDL documentation not found\n" unless defined $pdldoc;
69  
70 return $pdldoc;
71 }
72  
73 1;