| 1 | package CogWiki; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | extends 'Cog::App'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use constant webapp_class => 'CogWiki::WebApp'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use constant maker_class => 'CogWiki::Maker'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | package CogWiki::WebApp; | ||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Mo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | extends 'Cog::WebApp'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use constant SHARE_DIST => 'CogWiki'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use constant url_map => [ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | '()', | ||||||||||||||||||||||||||||
| 17 | ['/' => 'redirect', ('/pages/')], | ||||||||||||||||||||||||||||
| 18 | ['/home/?' => 'home_page'], | ||||||||||||||||||||||||||||
| 19 | ['/pages/?' => 'page_list'], | ||||||||||||||||||||||||||||
| 20 | ['/page/([A-Z0-9]{4})/?' => 'page_display', ('$1')], | ||||||||||||||||||||||||||||
| 21 | ['/page/name/([^/]+)/?' => 'page_by_name', ('$1')], | ||||||||||||||||||||||||||||
| 22 | ['/tags/' => 'tag_list' ], | ||||||||||||||||||||||||||||
| 23 | ['/tag/([^/]+)/?' => 'tag_page_list', ('$1')], | ||||||||||||||||||||||||||||
| 24 | 2 | ]; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use constant site_navigation => [ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | '()', | ||||||||||||||||||||||||||||
| 28 | ['Home' => '/home/'], | ||||||||||||||||||||||||||||
| 29 | ['Recent Changes' => '/pages/'], | ||||||||||||||||||||||||||||
| 30 | ['Tags' => '/tags/'], | ||||||||||||||||||||||||||||
| 31 | 2 | ]; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | package CogWiki::Maker; | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use Mo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | extends 'Cog::Maker'; | |||||||||||||||||||||||||||
| 36 | 2 | ▶ | use IO::All; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub all_files { | ||||||||||||||||||||||||||
|
Subroutine
all_files: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | return grep { | ||||||||||||||||||||||||||||
| 41 | 0 | $_->filename =~ /\.cog$/; | |||||||||||||||||||||||||||
| 42 | } io($self->config->content_root)->all_files; | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub make_cache { | ||||||||||||||||||||||||||
|
Subroutine
make_cache: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | 0 | io('cache')->mkdir; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | my $time = time; | |||||||||||||||||||||||||||
| 50 | 0 | my $page_list = []; | |||||||||||||||||||||||||||
| 51 | 0 | my $blobs = {}; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | $self->config->store->delete_tag_index; # XXX Temporary solution until can do smarter | |||||||||||||||||||||||||||
| 54 | 0 | for my $page_file ($self->all_files) { | |||||||||||||||||||||||||||
| 55 | 0 | my $page = $self->config->classes->{page}->from_text($page_file->all); | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $id = $page->Short or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | for my $Name (@{$page->Name}) { | |||||||||||||||||||||||||||
| 59 | 0 | my $name = $self->config->store->index_name($Name, $id); | |||||||||||||||||||||||||||
| 60 | 0 | io->file("cache/name/$name.txt")->assert->print($id); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | $self->config->store->index_tag($_, $id) | ||||||||||||||||||||||||||||
| 64 | 0 | for $self->all_tags($page); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $blob = { | |||||||||||||||||||||||||||
| 67 | %$page, | ||||||||||||||||||||||||||||
| 68 | Id => $id, | ||||||||||||||||||||||||||||
| 69 | Type => $page->Type, | ||||||||||||||||||||||||||||
| 70 | Title => $page->Title, | ||||||||||||||||||||||||||||
| 71 | Time => $page->Time, | ||||||||||||||||||||||||||||
| 72 | size => length($page->Content), | ||||||||||||||||||||||||||||
| 73 | duration => $page->duration, | ||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||
| 75 | 0 | delete $blob->{Content}; | |||||||||||||||||||||||||||
| 76 | 0 | delete $blob->{Name}; | |||||||||||||||||||||||||||
| 77 | 0 | push @$page_list, $blob; | |||||||||||||||||||||||||||
| 78 | 0 | $blobs->{$id} = $blob; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | $self->make_page_html($page, $page_file); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | delete $page->{content}; | |||||||||||||||||||||||||||
| 83 | 0 | io("cache/$id.json")->print($self->json->encode($blob)); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | io("cache/page-list.json")->print($self->json->encode($page_list)); | |||||||||||||||||||||||||||
| 86 | 0 | $self->make_tag_cloud($blobs); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub make_page_html { | ||||||||||||||||||||||||||
|
Subroutine
make_page_html: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | 0 | my $page = shift; | |||||||||||||||||||||||||||
| 92 | 0 | my $page_file = shift; | |||||||||||||||||||||||||||
| 93 | 0 | my $id = $page->Short; | |||||||||||||||||||||||||||
| 94 | 0 | my $html_filename = "cache/$id.html"; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return if -e $html_filename and -M $html_filename < -M $page_file->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $html_filename and -M $html_filename < -M $page_file->name
MC/DC0%0/2
-e $html_filename and -M $html_filename < -M $page_file->name
-e $html_filename
-M $html_filename < -M $page_file->name
Truth table0%0/3
A and B
A= -e $html_filenameB= -M $html_filename < -M $page_file->name
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $markup = $page->markup || 'simple'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$page->markup || 'simple'
MC/DC0%0/1
$page->markup || 'simple'
$page->markup
Truth table0%0/2
A
A= $page->markup
| |||||||||||||||||||||||||||||
| 99 | 0 | my $method = "${markup}_to_html"; | |||||||||||||||||||||||||||
| 100 | 0 | my $html = $self->$method($page->Content); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | print $page_file->filename . " -> $html_filename\n"; | |||||||||||||||||||||||||||
| 103 | 0 | io($html_filename)->assert->print($html); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub html_to_html { | ||||||||||||||||||||||||||
|
Subroutine
html_to_html: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 107 | 0 | return $_[1]; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub txt_to_html { | ||||||||||||||||||||||||||
|
Subroutine
txt_to_html: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | my $html = shift; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | $html =~ s/&/&/g; | |||||||||||||||||||||||||||
| 115 | 0 | $html =~ s/</</g; | |||||||||||||||||||||||||||
| 116 | 0 | $html =~ s/>/>/g; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | $html = "<pre>$html</pre>\n"; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return $html; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub pod_to_html { | ||||||||||||||||||||||||||
|
Subroutine
pod_to_html: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 125 | 0 | my $pod = shift; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | my $html; | |||||||||||||||||||||||||||
| 128 | 0 | my $p = Pod::Simple::HTML->new; | |||||||||||||||||||||||||||
| 129 | 0 | $p->output_string(\$html); | |||||||||||||||||||||||||||
| 130 | 0 | $p->parse_string_document($pod); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $html =~ s/.*!-- start doc -->(.*?)<!-- end doc --.*/$1/s or die; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | return $html; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub asc_to_html { | ||||||||||||||||||||||||||
|
Subroutine
asc_to_html: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | 0 | my $asciidoc = shift; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | my ($in, $out, $err) = ($asciidoc, '', ''); | |||||||||||||||||||||||||||
| 142 | 0 | my @cmd = qw(asciidoc -s -); | |||||||||||||||||||||||||||
| 143 | 0 | IPC::Run::run(\@cmd, \$in, \$out, \$err, IPC::Run::timeout(30)); | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | return $out; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub simple_to_html { | ||||||||||||||||||||||||||
|
Subroutine
simple_to_html: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 149 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 150 | 0 | my $text = shift; | |||||||||||||||||||||||||||
| 151 | return join '', map { | ||||||||||||||||||||||||||||
| 152 | 0 | chomp; | |||||||||||||||||||||||||||
| 153 | 0 | s/&/&/g; | |||||||||||||||||||||||||||
| 154 | 0 | s/</</g; | |||||||||||||||||||||||||||
| 155 | 0 | s/>/>/g; | |||||||||||||||||||||||||||
| 156 | 0 | s!(^|\n)( +)!$1 . ' ' x length($2)!ge; | |||||||||||||||||||||||||||
| 157 | 0 | s!\n!<br />\n!g; | |||||||||||||||||||||||||||
| 158 | 0 | "<p>$_</p>\n\n"; | |||||||||||||||||||||||||||
| 159 | } split /\n\n+/, $text; | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | 1; | |||||||||||||||||||||||||||