RosettaCode/Task.pm

filter: Statementstmt 23.2% 26 / 112 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 17.7% 31 / 175 CC 23 SCAR 43.2
CC
23
Cov
17%
build_task
132.0
parse_head_section
90.0
fetch_task
12.0
CRAP 75.5
↑ Summary RosettaCode.pm »
1 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package RosettaCode::Task;
3  
4 1 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Mo qw'build default xxx';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 extends 'RosettaCode';
10  
11 1 has name => '';
12 1 has path => '';
13 1 has url => '';
14 1 has meta => {};
15 1 has lang => '';
16 1 has prog => [];
17 1 has tasks => {};
18 1 has langs => {};
19 1 has bot => '';
20  
21 0 ▶sub fetch_task {
Subroutine fetch_task: not called CC=3 SCAR=24.8
Pod undocumented
22 0 my ($self) = @_;
23 0 my $file = io->file("Cache/Task/$self->{path}")->utf8;
24  
25 0 ▶ if ($file->exists and time - $file->mtime < $self->CACHE_TIME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->exists and time - $file->mtime < $self->CACHE_TIME) { } 0 0 0
Condition0%0/3
$file->exists and time - $file->mtime < $self->CACHE_TIME
!ll&&!rl&&r
000
MC/DC0%0/2
$file->exists and time - $file->mtime < $self->CACHE_TIME
$file->exists time - $file->mtime < $self->CACHE_TIME
Truth table0%0/3
A and B
A= $file->existsB= time - $file->mtime < $self->CACHE_TIME
ABresult
0X0
100
111
26 0 $self->text($file->all);
27 }
28 else {
29 0 my $text = $self->get_text($self->name);
30 0 $file->assert->print($text);
31 0 $self->text($text);
32 }
33 }
34  
35 0 ▶sub build_task {
Subroutine build_task: not called CC=11 SCAR=48.8
Pod undocumented
36 0 my ($self) = @_;
37  
38 0 my $name = $self->name;
39 0 my $text = $self->text;
40 0 $text =~ s/\r//g;
41 0 ▶ $text =~ s/\n?\z/\n/ if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 0 0 0
42  
43 0 $self->log("TASK $name");
44 0 my @sections = split /^==+ ?\{\{header\|(.+?)\}\}.*\n/m, $text;
45 0 ▶ if (@sections < 3 or $text !~ /<syntaxhighlight/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sections < 3 or not $text =~ /<syntaxhighlight/) 0 0 0
Condition0%0/3
@sections < 3 or not $text =~ /<syntaxhighlight/
l!l&&r!l&&!r
000
MC/DC0%0/2
@sections < 3 or not $text =~ /<syntaxhighlight/
@sections < 3 not $text =~ /<syntaxhighlight/
Truth table0%0/3
A or not(B)
A= @sections < 3B= not $text =~ /<syntaxhighlight/
ABresult
1X1
011
000
46 0 $self->log("ERROR: No implementations for '$name'");
47 }
48 0 my $head_section = shift @sections;
49 0 ▶ if (@sections % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sections % 2) 0 0 0
50 0 $self->log("ERROR: Bad task page for '$name'");
51 0 return;
52 }
53 0 $self->parse_head_section($head_section);
54 0 my $path = $self->path;
55 0 my $file = lc($path);
56  
57 0 ▶ while (@sections) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sections) 0 0 0
58 0 my ($lang, $text) = splice(@sections, 0, 2);
59 0 $lang =~ s/\|.*//;
60 0 $self->log(" $lang");
61 0 my $info = $self->langs->{lc $lang};
62 0 ▶ if (not defined $info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info) 0 0 0
63 0 $self->log("ERROR: Unknown lang '$lang' ($name)");
64 0 next;
65 }
66 0 $self->parse_task_lang_section($text, $lang);
67 0 my $programs = $self->prog;
68 0 ▶ next unless @$programs;
Branch: 1 branch
BranchTrueFalseTotal
unless @$programs 0 0 0
69 0 my $lang_path = $info->{path};
70 0 my $ext = $info->{ext};
71 0 my $source = "Lang/$lang_path/$path";
72 0 my $target = "../../Task/$path/$lang_path";
73 0 $self->write_symlink($source, $target, 2);
74 0 ▶ if (@$programs == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$programs == 1) 0 0 0
75 0 $self->write_file(
76 "Task/$path/$lang_path/$file.$ext",
77 $programs->[0],
78 2,
79 );
80 0 next;
81 }
82 0 my $count = 1;
83 0 for (@$programs) {
84 0 $self->write_file(
85 "Task/$path/$lang_path/$file-$count.$ext",
86 $_,
87 2,
88 );
89 0 $count++;
90 }
91 }
92  
93 0 $self->meta->{from} = "http://rosettacode.org/wiki/$self->{url}";
94 $self->write_file(
95 "Task/$path/00-TASK.txt",
96 delete $self->meta->{description},
97 0 1,
98 );
99 $self->dump_file(
100 "Task/$path/00-META.yaml",
101 $self->meta,
102 1,
103 0 ▶ ) if %{$self->meta};
Branch: 1 branch
BranchTrueFalseTotal
if %{$self->meta;} 0 0 0
104 }
105  
106 0 ▶sub parse_head_section {
Subroutine parse_head_section: not called CC=9 SCAR=45.0
Pod undocumented
107 0 my ($self, $text) = @_;
108 0 $_ = $text;
109 0 my $meta = $self->meta({});
110  
111 0 my $length = length;
112 0 while (1) {
113 0 s/\A<!--.*-->\s*//;
114 0 s/\A\[\[File:.*\s*//;
115 0 s/\A\{\{alertbox\|.*\n\s*//;
116 0 s/\A\{\{[Cc]larified-review\}\}\s*//;
117 0 s/\A\{\{[Cc]larify task\}\}\s*//;
118 0 s/\A\{\{[Oo]mit from\|.*\}\}\s*//;
119 0 s/\A\[\[[Ff]ile:.*\]\]\s*//;
120 0 s/\A\{\{[Ww]ikipedia[^\}]*\}\}\s*//;
121  
122 0 ▶ if (s/\A\s*\{\{requires\|(\w[\w ]*)\}\}\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/\A\s*\{\{requires\|(\w[\w ]*)\}\}\s*//) 0 0 0
123 0 ▶ $meta->{requires} ||= [];
Condition0%0/2
$meta->{"requires"} ||= []
l!l
00
MC/DC0%0/1
$meta->{"requires"} ||= []
$meta->{"requires"}
Truth table0%0/2
A
A= $meta->{"requires"}
Aresult
11
00
124 0 push @{$meta->{requires}}, $1;
125 }
126 0 ▶ if (s/\A\s*\[\[Category: *(\w[\w ]*)\]\]\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/\A\s*\[\[Category: *(\w[\w ]*)\]\]\s*//) 0 0 0
127 0 ▶ $meta->{category} ||= [];
Condition0%0/2
$meta->{"category"} ||= []
l!l
00
MC/DC0%0/1
$meta->{"category"} ||= []
$meta->{"category"}
Truth table0%0/2
A
A= $meta->{"category"}
Aresult
11
00
128 0 push @{$meta->{category}}, $1;
129 }
130 0 ▶ if (s/\A\{\{(?:[Dd]raft\s+)?[Tt]ask(?:\|([^\}]*?))?\}\}\s*//s) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/\A\{\{(?:[Dd]raft\s+)?[Tt]ask(?:\|([^\}]*?))?\}\}\s*//s) 0 0 0
131 0 ▶ $meta->{note} = $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
132 }
133  
134 0 ▶ last if length == $length;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ == $length 0 0 0
135 0 $length = length;
136 }
137  
138 # Get task description text:
139 0 ▶ $meta->{description} = $_ if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 0 0
140 }
141  
142 0 ▶sub parse_task_lang_section {
Subroutine parse_task_lang_section: not called CC=3 SCAR=24.8
Pod undocumented
143 0 my ($self, $text, $lang) = @_;
144 0 local $_ = $text;
145 0 $self->lang($lang);
146 0 my $programs = $self->prog([]);
147  
148 0 ▶ while (s/<syntaxhighlight.*?>(.*?)(?:<\/syntaxhighlight>|\z)//si) {
Branch: 1 branch
BranchTrueFalseTotal
if (s[<syntaxhighlight.*?>(.*?)(?:</syntaxhighlight>|\z)][]is) 0 0 0
149 0 my $program = $1;
150 0 $program =~ s/\A\s*\n//;
151 0 $program =~ s/ *$//mg;
152 0 ▶ $program =~ s/\n*\z/\n/ if length($program);
Branch: 1 branch
BranchTrueFalseTotal
if length $program 0 0 0
153 0 push @$programs, $program;
154 }
155 }
156  
157 1 1;
↑ Summary RosettaCode.pm »