Perl6/Document.pm untested

filter: Statementstmt 0.0% 0 / 93 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 170 CC 10 SCAR 23.7
CC
10
Cov
0%
_check_syntax_internals
30.0
get_outline
30.0
get_command
6.0
CRAP 10.7
1 package Padre::Plugin::Perl6::Document;
2 BEGIN {
3 $Padre::Plugin::Perl6::Document::VERSION = '0.71';
4 }
5  
6 # ABSTRACT: Perl 6 Support Document
7  
8 use 5.010;
9 use strict;
10 use warnings;
11  
12 use Padre::Wx ();
13 use Padre::Document ();
14  
15 our @ISA = 'Padre::Document';
16  
17 # Task Integration
18 sub task_functions {
19  
20 # There is no actual need to support it
21 # We already have outline support
22 return;
23 }
24  
25 sub task_outline {
26 return 'Padre::Plugin::Perl6::Outline';
27 }
28  
29 sub task_syntax {
30 return 'Padre::Plugin::Perl6::Syntax';
31 }
32  
33 # get Perl6 (rakudo) command line for "Run script" F5 Padre menu item
34 sub get_command {
35 my $self = shift;
36  
37 my $filename = $self->filename;
38 require Padre::Plugin::Perl6::Util;
39 my $perl6 = Padre::Plugin::Perl6::Util::perl6_exe();
40  
41 if ( not $perl6 ) {
42 my $main = Padre->ide->wx->main;
43 $main->error(
44 "Either perl6 needs to be in the PATH or RAKUDO_DIR must point to the directory of the Rakudo checkout.");
45 return;
46 }
47  
48 return qq{"$perl6" "$filename"};
49 }
50  
51 # Checks the syntax of a Perl document.
52 # Documented in Padre::Document!
53 # Implemented as a task. See Padre::Plugin::Perl6::Syntax
54 sub check_syntax {
55 shift->_check_syntax_internals(
56  
57 # Passing all arguments is ok, but critic complains
58 { @_, ## no critic (ProhibitCommaSeparatedStatements)
59 background => 0
60 }
61 );
62 }
63  
64 sub check_syntax_in_background {
65 shift->_check_syntax_internals(
66  
67 # Passing all arguments is ok, but critic complains
68 { @_, ## no critic (ProhibitCommaSeparatedStatements)
69 background => 1
70 }
71 );
72 }
73  
74 sub _check_syntax_internals {
75 my $self = shift;
76 my $args = shift;
77  
78 my $text = $self->text_with_one_nl;
79 unless ( defined $text and $text ne '' ) {
80 return [];
81 }
82  
83 # Do we really need an update?
84 require Digest::MD5;
85 my $md5 = Digest::MD5::md5_hex( Encode::encode_utf8($text) );
86 unless ( $args->{force} ) {
87 if ( defined( $self->{last_syncheck_md5} )
88 and $self->{last_syncheck_md5} eq $md5 )
89 {
90 return;
91 }
92 }
93 $self->{last_syncheck_md5} = $md5;
94  
95 require Padre::Plugin::Perl6::Syntax;
96 my $task = Padre::Plugin::Perl6::Syntax->new(
97 document => $self,
98 );
99  
100 if ( $args->{background} ) {
101  
102 # asynchroneous execution (see on_finish hook)
103 $task->schedule;
104 return;
105 } else {
106  
107 # serial execution, returning the result
108 $task->prepare or return;
109 $task->run;
110 $task->finish;
111 return $task->{model};
112 }
113 }
114  
115 # In Perl 6 the best way to comment the current error reliably is
116 # by putting a hash and a space since #( is an embedded comment in Perl 6!
117 # see S02:166
118 sub comment_lines_str {
119 return '# ';
120 }
121  
122 #
123 # Returns the Outline tree
124 #
125 sub get_outline {
126 my $self = shift;
127 my %args = @_;
128  
129 my $tokens = $self->{tokens};
130  
131 if ( not defined $tokens ) {
132 return;
133 }
134  
135 my $text = $self->text_get;
136 unless ( defined $text and $text ne '' ) {
137 return [];
138 }
139  
140 # Do we really need an update?
141 require Digest::MD5;
142 my $md5 = Digest::MD5::md5_hex( Encode::encode_utf8($text) );
143 unless ( $args{force} ) {
144 if ( defined( $self->{last_outline_md5} )
145 and $self->{last_outline_md5} eq $md5 )
146 {
147 return;
148 }
149 }
150 $self->{last_outline_md5} = $md5;
151  
152 require Padre::Plugin::Perl6::Outline;
153 my $task = Padre::Plugin::Perl6::Outline->new(
154 document => $self,
155 );
156  
157 # asynchronous execution (see on_finish hook)
158 $task->schedule;
159 return;
160 }
161  
162 #
163 # Returns the help provider
164 #
165 sub get_help_provider {
166 require Padre::Plugin::Perl6::Help;
167 return Padre::Plugin::Perl6::Help->new;
168 }
169  
170 #
171 # Returns the quick fix provider
172 #
173 sub get_quick_fix_provider {
174 require Padre::Plugin::Perl6::QuickFix;
175 return Padre::Plugin::Perl6::QuickFix->new;
176 }
177  
178 1;
179  
180 __END__