lib/App/Dapper/MCP.pm

filter: Statementstmt 15.9% 52 / 326 Branchbran 0.0% 0 / 192 Conditioncond 0.0% 0 / 52 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 40.0% 16 / 40 Podpod 100% 20 / 20 totaltotal 13.3% 88 / 661 CC 118 SCAR 46.9
CC
118
Cov
9%
handle
380.0
write_layout
210.0
write_page
132.0
CRAP 108.4
« lib/App/Dapper/Collections.pm ↑ Summary lib/App/Dapper/Init.pm »
1 package App::Dapper::MCP;
2  
3 =head1 NAME
4  
5 App::Dapper::MCP - Let AI assistants work on a Dapper site over MCP.
6  
7 =head1 DESCRIPTION
8  
9 C<dapper mcp> runs a Model Context Protocol server on standard input and
10 output, so that an AI assistant (Claude, or any other MCP client) can read,
11 write, build and check a site through Dapper, with Dapper's rules as
12 guardrails: pages are only written inside the source directory, and a page
13 that doesn't match its C<_schema.yml> is refused rather than written.
14  
15 To add it to Claude Code:
16  
17 $ claude mcp add dapper -- dapper -C /path/to/site mcp
18  
19 Other clients take a command and arguments in their configuration:
20  
21 { "command": "dapper", "args": ["-C", "/path/to/site", "mcp"] }
22  
23 =head2 Prompts and resources
24  
25 The server also offers prompts for common jobs (C<new_site>, C<write_post>,
26 C<audit_site>) and resources an assistant can read: C<dapper://guide> (the
27 same guide as C<AGENTS.md>), C<dapper://config> and C<dapper://schemas>.
28  
29 =head2 Tools
30  
31 =over 4
32  
33 =item B<site_info>
34  
35 The site's settings, directories, categories, tags and schemas.
36  
37 =item B<list_pages>
38  
39 Every page (optionally only those in a C<category> or with a C<tag>), with
40 its source file, URL, title, date, categories and tags.
41  
42 =item B<read_page>
43  
44 A page's front matter and body, given its source file.
45  
46 =item B<write_page>
47  
48 Create or replace a page from front matter and a body. The page is checked
49 against its schema first and is not written if it doesn't match.
50  
51 =item B<rename_page>
52  
53 Move or rename a page; if its URL changes, a redirect from the old URL is
54 added to C<_data/redirects.yml>.
55  
56 =item B<read_layout>, B<write_layout>
57  
58 Read a layout, or create or replace one (it is parsed first and not saved if
59 it has an error).
60  
61 =item B<build>
62  
63 Build the site.
64  
65 =item B<check>
66  
67 Find problems without touching the output directory (see
68 L<App::Dapper::Check>).
69  
70 =back
71  
72 =cut
73  
74 32 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 32 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 32 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
80 32 ▶use YAML::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 32 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 32 ▶use File::Spec::Functions qw/ canonpath catfile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 32 ▶use File::Basename qw/ dirname /;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 32 ▶use File::Path qw/ make_path /;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 32 ▶use Template::Alloy;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 32 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
87 32 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 32 ▶use App::Dapper::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 32 ▶use App::Dapper::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 32 ▶use App::Dapper::Agents;
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 32 my $PROTOCOL_VERSION = '2025-06-18';
94  
95 32 my @TOOLS = (
96 {
97 name => 'site_info',
98 description => 'Describe the Dapper site: its settings, directories, number of pages, categories, tags, and the front matter schemas pages must follow.',
99 inputSchema => { type => 'object', properties => {} },
100 },
101 {
102 name => 'list_pages',
103 description => 'List the pages of the site with their source file, URL, title, date, categories and tags. Optionally only pages in a category or with a tag.',
104 inputSchema => {
105 type => 'object',
106 properties => {
107 category => { type => 'string', description => 'Only pages in this category' },
108 tag => { type => 'string', description => 'Only pages with this tag' },
109 },
110 },
111 },
112 {
113 name => 'read_page',
114 description => 'Read a page: its front matter (as an object) and its body (Markdown or HTML).',
115 inputSchema => {
116 type => 'object',
117 properties => {
118 source => { type => 'string', description => 'The source file, e.g. blog/my-post.md (relative to the source directory)' },
119 },
120 required => ['source'],
121 },
122 },
123 {
124 name => 'write_page',
125 description => 'Create or replace a page in the source directory. The front matter is checked against the nearest _schema.yml first; if it does not match, nothing is written and the problems are returned. Run check or build afterwards.',
126 inputSchema => {
127 type => 'object',
128 properties => {
129 source => { type => 'string', description => 'The source file to write, e.g. blog/my-post.md (relative to the source directory)' },
130 front_matter => { type => 'object', description => 'The page settings, e.g. {"title": "...", "date": "2026-01-01T09:00:00", "categories": ["blog"]}' },
131 body => { type => 'string', description => 'The page content, in Markdown for .md files' },
132 overwrite => { type => 'boolean', description => 'Replace the file if it already exists (default false)' },
133 },
134 required => ['source', 'front_matter', 'body'],
135 },
136 },
137 {
138 name => 'rename_page',
139 description => 'Move or rename a page. If its URL changes, a redirect from the old URL is added to _data/redirects.yml so links keep working. Refused if the page would not match the schema of its new folder.',
140 inputSchema => {
141 type => 'object',
142 properties => {
143 source => { type => 'string', description => 'The page to move, e.g. blog/old-name.md' },
144 new_source => { type => 'string', description => 'Where to move it, e.g. blog/new-name.md' },
145 },
146 required => ['source', 'new_source'],
147 },
148 },
149 {
150 name => 'read_layout',
151 description => 'Read a layout (a template in the layout directory), e.g. "post".',
152 inputSchema => {
153 type => 'object',
154 properties => { name => { type => 'string', description => 'The layout name, without .html' } },
155 required => ['name'],
156 },
157 },
158 {
159 name => 'write_layout',
160 description => 'Create or replace a layout. The template is parsed first and not saved if it has a syntax error. Layouts use Template Toolkit syntax: [% page.content %], [% page.title %], [% site.name %].',
161 inputSchema => {
162 type => 'object',
163 properties => {
164 name => { type => 'string', description => 'The layout name, without .html (letters, digits, - and _)' },
165 content => { type => 'string', description => 'The whole layout, optionally starting with front matter (layout: to wrap it in another layout, description: to explain it)' },
166 overwrite => { type => 'boolean', description => 'Replace an existing layout (default false)' },
167 },
168 required => ['name', 'content'],
169 },
170 },
171 {
172 name => 'build',
173 description => 'Build the site into the output directory.',
174 inputSchema => { type => 'object', properties => {} },
175 },
176 {
177 name => 'check',
178 description => 'Check the site for problems (front matter, schemas, layouts, templates, broken links) without touching the output directory.',
179 inputSchema => { type => 'object', properties => {} },
180 },
181 );
182  
183 32 my @PROMPTS = (
184 {
185 name => 'new_site',
186 description => 'Turn this project into a new site from a description of what it is for.',
187 arguments => [ { name => 'description', description => 'What the site is for and what it should contain', required => JSON::true } ],
188 },
189 {
190 name => 'write_post',
191 description => 'Write a new post or page that matches the site\'s schemas.',
192 arguments => [
193 { name => 'topic', description => 'What the post is about', required => JSON::true },
194 { name => 'category', description => 'The category to put it in (optional)', required => JSON::false },
195 ],
196 },
197 {
198 name => 'audit_site',
199 description => 'Check the whole site for problems and fix them.',
200 arguments => [],
201 },
202 );
203  
204 32 my @RESOURCES = (
205 { uri => 'dapper://guide', name => 'Guide to this site', description => 'How this Dapper project works: commands, folders, layouts, schemas and rules (the same as AGENTS.md).', mimeType => 'text/markdown' },
206 { uri => 'dapper://config', name => 'Project file', description => 'The site\'s settings (_config.yml).', mimeType => 'text/yaml' },
207 { uri => 'dapper://schemas', name => 'Schemas', description => 'The front matter rules for each folder, as JSON.', mimeType => 'application/json' },
208 );
209  
210 =head2 serve
211  
212 Takes a Dapper object, and answers MCP requests from standard input on
213 standard output until standard input closes.
214  
215 =cut
216  
217 0 ▶sub serve {
Subroutine serve: not called CC=8 SCAR=42.8
Pod documented
218 0 my ($dapper) = @_;
219  
220 # Responses go to the real standard output; anything else that would be
221 # printed while a tool runs (such as Pagefind's output) goes to standard
222 # error, so that it can't corrupt the conversation
223 0 ▶ open(my $out, '>&', \*STDOUT) or die "error: could not open standard output: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">&", \*STDOUT or die "error: could not open standard output: $!\n" 0 0 0
224 0 binmode($out, ':raw');
225 0 $out->autoflush(1);
226 0 ▶ open(STDOUT, '>&', \*STDERR) or die "error: could not redirect standard output: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", \*STDERR or die "error: could not redirect standard output: $!\n" 0 0 0
227 0 binmode(STDIN, ':raw');
228  
229 0 my $json = JSON->new->utf8->canonical;
230  
231 0 ▶ while (my $line = <STDIN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline STDIN)) 0 0 0
232 0 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 0 0
233  
234 0 my $request = eval { $json->decode($line) };
235 0 ▶ if (not $request or ref $request ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $request or ref $request ne "HASH") 0 0 0
Condition0%0/3
not $request or ref $request ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $request or ref $request ne "HASH"
not $request ref $request ne "HASH"
Truth table0%0/3
not(A) or B
A= not $requestB= ref $request ne "HASH"
ABresult
1X1
011
000
236 0 print $out $json->encode({ jsonrpc => '2.0', id => undef,
237 error => { code => -32700, message => 'Parse error' } }), "\n";
238 0 next;
239 }
240  
241 0 my $response = handle($dapper, $request);
242 0 ▶ print $out $json->encode($response), "\n" if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
243 }
244 }
245  
246 =head2 handle
247  
248 Takes a Dapper object and a JSON-RPC request, and returns the response (or
249 nothing, for notifications).
250  
251 =cut
252  
253 0 ▶sub handle {
Subroutine handle: not called CC=19 SCAR=59.4
Pod documented
254 0 my ($dapper, $request) = @_;
255  
256 0 my $id = $request->{id};
257 0 ▶ my $method = defined $request->{method} ? $request->{method} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $request->{'method'} ? : 0 0 0
258 0 ▶ my $params = ref $request->{params} eq 'HASH' ? $request->{params} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $request->{'params'} eq 'HASH' ? : 0 0 0
259  
260 0 ▶ return if not defined $id; # a notification, such as notifications/initialized
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 0 0
261  
262 0 my $result;
263 0 ▶ if ($method eq 'initialize') {
Branch: 8 branches
BranchTrueFalseTotal
if ($method eq 'initialize') { } 0 0 0
elsif ($method eq 'ping') { } 0 0 0
elsif ($method eq 'tools/list') { } 0 0 0
elsif ($method eq 'prompts/list') { } 0 0 0
elsif ($method eq 'prompts/get') { } 0 0 0
elsif ($method eq 'resources/list') { } 0 0 0
elsif ($method eq 'resources/read') { } 0 0 0
elsif ($method eq 'tools/call') { } 0 0 0
264 0 my $requested = $params->{protocolVersion};
265 0 ▶ $result = {
Branch: 1 branch
BranchTrueFalseTotal
defined $requested ? : 0 0 0
266 protocolVersion => defined $requested ? $requested : $PROTOCOL_VERSION,
267 capabilities => { tools => {}, prompts => {}, resources => {} },
268 serverInfo => { name => 'dapper', version => "$App::Dapper::VERSION" },
269 instructions => 'Dapper builds a static website from Markdown and HTML files with YAML front matter. '
270 . 'Use site_info first to learn the site\'s schemas and categories, write_page to create pages '
271 . '(it refuses pages that do not match their schema), then check to find problems and build to publish.',
272 };
273 }
274 elsif ($method eq 'ping') {
275 0 $result = {};
276 }
277 elsif ($method eq 'tools/list') {
278 0 $result = { tools => \@TOOLS };
279 }
280 elsif ($method eq 'prompts/list') {
281 0 $result = { prompts => \@PROMPTS };
282 }
283 elsif ($method eq 'prompts/get') {
284 0 ▶ my $prompt = get_prompt($dapper, $params->{name}, ref $params->{arguments} eq 'HASH' ? $params->{arguments} : {});
Branch: 1 branch
BranchTrueFalseTotal
ref $params->{'arguments'} eq 'HASH' ? : 0 0 0
285 0 ▶ return { jsonrpc => '2.0', id => $id, error => { code => -32602, message => "There is no prompt called \"" . (defined $params->{name} ? $params->{name} : '') . "\"" } }
Branch: 2 branches
BranchTrueFalseTotal
unless $prompt 0 0 0
defined $params->{'name'} ? : 0 0 0
286 unless $prompt;
287 0 $result = $prompt;
288 }
289 elsif ($method eq 'resources/list') {
290 0 $result = { resources => \@RESOURCES };
291 }
292 elsif ($method eq 'resources/read') {
293 0 my $contents = read_resource($dapper, $params->{uri});
294 0 ▶ return { jsonrpc => '2.0', id => $id, error => { code => -32002, message => "Resource not found: " . (defined $params->{uri} ? $params->{uri} : '') } }
Branch: 2 branches
BranchTrueFalseTotal
unless $contents 0 0 0
defined $params->{'uri'} ? : 0 0 0
295 unless $contents;
296 0 $result = { contents => [ $contents ] };
297 }
298 elsif ($method eq 'tools/call') {
299 0 ▶ $result = call_tool($dapper, $params->{name}, ref $params->{arguments} eq 'HASH' ? $params->{arguments} : {});
Branch: 1 branch
BranchTrueFalseTotal
ref $params->{'arguments'} eq 'HASH' ? : 0 0 0
300 }
301 else {
302 0 return { jsonrpc => '2.0', id => $id, error => { code => -32601, message => "Method not found: $method" } };
303 }
304  
305 0 return { jsonrpc => '2.0', id => $id, result => $result };
306 }
307  
308 =head2 get_prompt
309  
310 Takes a Dapper object, a prompt name and its arguments, and returns the
311 prompt's messages, or nothing if there is no such prompt.
312  
313 =cut
314  
315 0 ▶sub get_prompt {
Subroutine get_prompt: not called CC=9 SCAR=45.0
Pod documented
316 0 my ($dapper, $name, $args) = @_;
317  
318 0 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
319  
320 0 my $steps = "Work through the dapper MCP tools: start with site_info to learn the schemas, "
321 . "categories and layouts; use write_page for every page (it refuses pages that don't match "
322 . "their schema, so fix what it reports); run check until it reports no errors; then build.";
323  
324 0 my $text;
325 0 ▶ if ($name eq 'new_site') {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'new_site') { } 0 0 0
elsif ($name eq 'write_post') { } 0 0 0
elsif ($name eq 'audit_site') { } 0 0 0
326 0 ▶ my $description = defined $args->{description} ? $args->{description} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'description'} ? : 0 0 0
327 0 $text = "Turn this Dapper project into this site:\n\n$description\n\n"
328 . "Write the home page and the other pages the site needs, with a title and a description on each, "
329 . "and replace any placeholder text from the starter template. Keep to the existing layouts and schemas. "
330 . "Read the dapper://guide resource for this project's conventions. $steps";
331 }
332 elsif ($name eq 'write_post') {
333 0 ▶ my $topic = defined $args->{topic} ? $args->{topic} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'topic'} ? : 0 0 0
334 0 ▶ my $category = defined $args->{category} && length $args->{category} ? " in the \"$args->{category}\" category" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'category'} && length $args->{'category'} ? : 0 0 0
Condition0%0/3
defined $args->{"category"} and length $args->{"category"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args->{"category"} and length $args->{"category"}
defined $args->{"category"} length $args->{"category"}
Truth table0%0/3
A and B
A= defined $args->{"category"}B= length $args->{"category"}
ABresult
0X0
100
111
335 0 $text = "Write a new post$category about:\n\n$topic\n\n"
336 . "Use today's date, a clear title, a description of about 150 characters, and tags that are already "
337 . "in use where they fit. Write it in Markdown, with a strong first paragraph (it becomes the excerpt). $steps";
338 }
339 elsif ($name eq 'audit_site') {
340 0 $text = "Audit this Dapper site. Run check and fix every error it reports. Then look for pages without a "
341 . "description, placeholder text, outdated dates, and broken or vague links, and fix what you can with "
342 . "write_page. Finish with check and build, and summarize what you changed. $steps";
343 }
344 else {
345 0 return;
346 }
347  
348 return {
349 0 description => (grep { $_->{name} eq $name } @PROMPTS)[0]->{description},
350 0 messages => [ { role => 'user', content => { type => 'text', text => $text } } ],
351 };
352 }
353  
354 =head2 read_resource
355  
356 Takes a Dapper object and a resource URI, and returns its contents, or
357 nothing if there is no such resource.
358  
359 =cut
360  
361 0 ▶sub read_resource {
Subroutine read_resource: not called CC=6 SCAR=37.4
Pod documented
362 0 my ($dapper, $uri) = @_;
363  
364 0 ▶ return unless defined $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri 0 0 0
365  
366 0 ▶ if ($uri eq 'dapper://guide') {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri eq "dapper://guide") 0 0 0
367 0 return { uri => $uri, mimeType => 'text/markdown', text => App::Dapper::Agents::guide($dapper) };
368 }
369 0 ▶ if ($uri eq 'dapper://config') {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri eq "dapper://config") 0 0 0
370 0 ▶ my $text = -f $dapper->{config} ? App::Dapper::Utils::read_file($dapper->{config}) : '';
Branch: 1 branch
BranchTrueFalseTotal
-f $dapper->{'config'} ? : 0 0 0
371 0 return { uri => $uri, mimeType => 'text/yaml', text => $text };
372 }
373 0 ▶ if ($uri eq 'dapper://schemas') {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri eq "dapper://schemas") 0 0 0
374 0 my $info = site_info($dapper);
375 0 return { uri => $uri, mimeType => 'application/json', text => JSON->new->canonical->pretty->encode($info->{schemas}) };
376 }
377  
378 0 return;
379 }
380  
381 =head2 call_tool
382  
383 Takes a Dapper object, a tool name and its arguments, runs the tool, and
384 returns an MCP tool result.
385  
386 =cut
387  
388 0 ▶sub call_tool {
Subroutine call_tool: not called CC=5 SCAR=34.0
Pod documented
389 0 my ($dapper, $name, $args) = @_;
390  
391 0 my %tools = (
392 site_info => \&site_info,
393 list_pages => \&list_pages,
394 read_page => \&read_page,
395 write_page => \&write_page,
396 rename_page => \&rename_page,
397 read_layout => \&read_layout,
398 write_layout => \&write_layout,
399 build => \&build,
400 check => \&check,
401 );
402  
403 0 ▶ my $tool = defined $name ? $tools{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 0 0 0
404 0 ▶ return tool_result({ error => "There is no tool called \"" . (defined $name ? $name : '') . "\"." }, 1) unless $tool;
Branch: 2 branches
BranchTrueFalseTotal
unless $tool 0 0 0
defined $name ? : 0 0 0
405  
406 0 my ($data, $is_error);
407 0 ▶ eval { ($data, $is_error) = $tool->($dapper, $args); 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { () = &$tool($dapper, $args); 1 } } or do { (my $message = $@) =~ s/^error: //; $message =~ s/\s+\z//; () = ({"error", $message}, 1) } 0 0 0
408 0 (my $message = $@) =~ s/^error: //;
409 0 $message =~ s/\s+\z//;
410 0 ($data, $is_error) = ({ error => $message }, 1);
411 };
412  
413 0 return tool_result($data, $is_error);
414 }
415  
416 =head2 tool_result
417  
418 Takes a result (a hash) and whether it is an error, and returns it in the form
419 MCP expects: as JSON text, and as structured content.
420  
421 =cut
422  
423 0 ▶sub tool_result {
Subroutine tool_result: not called CC=2 SCAR=17.9
Pod documented
424 0 my ($data, $is_error) = @_;
425  
426 return {
427 0 ▶ content => [ { type => 'text', text => JSON->new->canonical->pretty->encode($data) } ],
Branch: 1 branch
BranchTrueFalseTotal
$is_error ? : 0 0 0
428 structuredContent => $data,
429 isError => $is_error ? JSON::true : JSON::false,
430 };
431 }
432  
433 # Read the project and source files without writing anything
434 0 ▶sub _load {
Subroutine _load: not called CC=1 SCAR=6.9
435 0 my ($dapper) = @_;
436  
437 0 local $dapper->{quiet} = 1;
438 0 $dapper->{problems} = [];
439 0 $dapper->{written} = {};
440 0 $dapper->{page_owner} = {};
441 0 $dapper->parse();
442 0 $dapper->transform();
443 }
444  
445 0 ▶sub _page_summary {
Subroutine _page_summary: not called CC=9 SCAR=45.0
446 0 my ($dapper, $page) = @_;
447  
448 0 my $source = $page->{source};
449 0 my $prefix = "$dapper->{source}/";
450 0 ▶ $source = substr($source, length $prefix) if index($source, $prefix) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($source, $prefix) == 0 0 0 0
451  
452 0 my %summary = (source => $source, url => $page->{url});
453 0 ▶ $summary{title} = $page->{title} if defined $page->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $page->{"title"} 0 0 0
454 0 ▶ $summary{date} = "$page->{date}" if defined $page->{date};
Branch: 1 branch
BranchTrueFalseTotal
if defined $page->{"date"} 0 0 0
455 0 ▶ $summary{layout} = $page->{layout} if defined $page->{layout};
Branch: 1 branch
BranchTrueFalseTotal
if defined $page->{"layout"} 0 0 0
456 0 for my $list (qw/ categories tags /) {
457 0 my $value = $page->{$list};
458 0 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
459 0 ▶ $summary{$list} = ref $value eq 'ARRAY' ? $value : [$value];
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 0 0 0
460 }
461 0 ▶ $summary{generated} = JSON::true if $page->{generated};
Branch: 1 branch
BranchTrueFalseTotal
if $page->{"generated"} 0 0 0
462 0 return \%summary;
463 }
464  
465 =head2 site_info
466  
467 The C<site_info> tool.
468  
469 =cut
470  
471 0 ▶sub site_info {
Subroutine site_info: not called CC=6 SCAR=37.4
Pod documented
472 0 my ($dapper) = @_;
473  
474 0 _load($dapper);
475 0 my $site = $dapper->{site};
476  
477 0 my %settings;
478 0 for my $key (sort keys %$site) {
479 0 ▶ next if $key =~ /^(?:pages|categories|tags|data|time|category_pages|tag_pages)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^(?:pages|categories|tags|data|time|category_pages|tag_pages)$/ 0 0 0
480 0 my $value = $site->{$key};
481 0 ▶ next if ref $value and ref $value ne 'HASH' and ref $value ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and ref $value ne "HASH" and ref $value ne "ARRAY" 0 0 0
Condition0%0/6
ref $value and ref $value ne "HASH" and ref $value ne "ARRAY"
!ll&&!rl&&r
000
ref $value and ref $value ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $value and ref $value ne "HASH" and ref $value ne "ARRAY"
ref $value ref $value ne "HASH" ref $value ne "ARRAY"
Truth table0%0/4
A and B and C
A= ref $valueB= ref $value ne "HASH"C= ref $value ne "ARRAY"
ABCresult
0XX0
10X0
1100
1111
482 0 $settings{$key} = $value;
483 }
484  
485 0 my @schemas;
486 File::Find::find({
487 no_chdir => 1,
488 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
489 0 ▶ return unless $_ =~ m{/_schema\.yml$};
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ m[/_schema\.yml$] 0 0 0
490 0 my $name = App::Dapper::Utils::name_chars($File::Find::name);
491 0 my $schema = eval { App::Dapper::Schema::load($name) };
492 0 my $dir = dirname($name);
493 push @schemas, $schema
494 ? { applies_to => $dir, file => $name, required => $schema->{required},
495 0 ▶ fields => $schema->{fields}, additional => $schema->{additional} ? JSON::true : JSON::false }
Branch: 2 branches
BranchTrueFalseTotal
$schema ? : 0 0 0
$schema->{'additional'} ? : 0 0 0
496 : { applies_to => $dir, file => $name, error => "$@" };
497 },
498 0 }, App::Dapper::Utils::name_bytes($dapper->{source}));
499  
500 return {
501 name => $site->{name},
502 url => $site->{url},
503 description => $site->{description},
504 directories => { source => $dapper->{source}, output => $dapper->{output}, layout => $dapper->{layout}, data => $dapper->{data_dir} },
505 0 pages => scalar @{$site->{pages}},
506 0 categories => { map { $_ => scalar @{$site->{categories}->{$_}} } keys %{$site->{categories}} },
507 0 tags => { map { $_ => scalar @{$site->{tags}->{$_}} } keys %{$site->{tags}} },
508 0 layouts => [ sort keys %{$dapper->{layout_content}} ],
509 0 schemas => [ sort { $a->{applies_to} cmp $b->{applies_to} } @schemas ],
510 settings => \%settings,
511 };
512 }
513  
514 =head2 list_pages
515  
516 The C<list_pages> tool.
517  
518 =cut
519  
520 0 ▶sub list_pages {
Subroutine list_pages: not called CC=5 SCAR=34.0
Pod documented
521 0 my ($dapper, $args) = @_;
522  
523 0 _load($dapper);
524 0 my $site = $dapper->{site};
525  
526 0 my @pages = @{$site->{pages}};
527 0 ▶ if (defined $args->{category}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args->{'category'}) { } 0 0 0
elsif (defined $args->{'tag'}) { } 0 0 0
528 0 ▶ @pages = reverse @{ $site->{categories}->{$args->{category}} || [] };
Condition0%0/2
$site->{'categories'}{$args->{'category'}} || []
l!l
00
MC/DC0%0/1
$site->{'categories'}{$args->{'category'}} || []
$site->{'categories'}{$args->{'category'}}
Truth table0%0/2
A
A= $site->{'categories'}{$args->{'category'}}
Aresult
11
00
529 }
530 elsif (defined $args->{tag}) {
531 0 ▶ @pages = reverse @{ $site->{tags}->{$args->{tag}} || [] };
Condition0%0/2
$site->{'tags'}{$args->{'tag'}} || []
l!l
00
MC/DC0%0/1
$site->{'tags'}{$args->{'tag'}} || []
$site->{'tags'}{$args->{'tag'}}
Truth table0%0/2
A
A= $site->{'tags'}{$args->{'tag'}}
Aresult
11
00
532 }
533  
534 0 return { pages => [ map { _page_summary($dapper, $_) } @pages ] };
535 }
536  
537 =head2 source_path
538  
539 Takes a Dapper object and a path given by a client, and returns the path of
540 the file in the source directory. Dies if the path would lead outside it.
541  
542 =cut
543  
544 0 ▶sub source_path {
Subroutine source_path: not called CC=7 SCAR=40.3
Pod documented
545 0 my ($dapper, $path) = @_;
546  
547 0 ▶ die "error: give the source file, e.g. blog/my-post.md\n" unless defined $path and length $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 0 0 0
Condition0%0/3
defined $path and length $path
!ll&&!rl&&r
000
MC/DC0%0/2
defined $path and length $path
defined $path length $path
Truth table0%0/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
548 0 ▶ die "error: \"$path\" must be relative to the source directory\n" if File::Spec->file_name_is_absolute($path);
Branch: 1 branch
BranchTrueFalseTotal
if "File::Spec"->file_name_is_absolute($path) 0 0 0
549  
550 0 my $source = canonpath($dapper->{source});
551 0 my $relative = canonpath($path);
552 0 ▶ $relative = substr($relative, length($source) + 1) if index($relative, "$source/") == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($relative, "$source/") == 0 0 0 0
553  
554 0 my @parts = File::Spec->splitdir($relative);
555 0 ▶ die "error: \"$path\" must not contain ..\n" if grep { $_ eq '..' } @parts;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "..";} @parts 0 0 0
556 0 ▶ die "error: \"$path\" must not be a hidden file\n" if grep { /^\./ } @parts;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^\./;} @parts 0 0 0
557  
558 0 return canonpath(catfile($source, $relative));
559 }
560  
561 =head2 read_page
562  
563 The C<read_page> tool.
564  
565 =cut
566  
567 0 ▶sub read_page {
Subroutine read_page: not called CC=3 SCAR=24.8
Pod documented
568 0 my ($dapper, $args) = @_;
569  
570 0 $dapper->read_project();
571 0 my $file = source_path($dapper, $args->{source});
572 0 ▶ die "error: there is no file \"$file\"\n" unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
573  
574 0 my $text = App::Dapper::Utils::read_file($file);
575 0 my ($front_matter, $body) = App::Dapper::Utils::split_frontmatter($text, $file);
576 0 ▶ return { source => $args->{source}, file => $file, front_matter => undef, body => $text } unless defined $front_matter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $front_matter 0 0 0
577  
578 0 $body =~ s/^(?:\r?\n)+//;
579 0 return { source => $args->{source}, file => $file, front_matter => $front_matter, body => $body };
580 }
581  
582 =head2 schema_for
583  
584 Takes a Dapper object and a file in the source directory, and returns the
585 schema that applies to it (from the nearest C<_schema.yml> at or above its
586 directory), or nothing.
587  
588 =cut
589  
590 0 ▶sub schema_for {
Subroutine schema_for: not called CC=5 SCAR=34.0
Pod documented
591 0 my ($dapper, $file) = @_;
592  
593 0 my $source = canonpath($dapper->{source});
594 0 my $dir = dirname($file);
595 0 while (1) {
596 0 my $schema_file = catfile($dir, '_schema.yml');
597 0 ▶ return App::Dapper::Schema::load($schema_file) if -f $schema_file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $schema_file 0 0 0
598 0 ▶ last if canonpath($dir) eq $source or $dir eq '.' or $dir eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if canonpath($dir) eq $source or $dir eq "." or $dir eq "/" 0 0 0
Condition0%0/6
canonpath($dir) eq $source or $dir eq "." or $dir eq "/"
l!l&&r!l&&!r
000
canonpath($dir) eq $source or $dir eq "."
l!l&&r!l&&!r
000
MC/DC0%0/3
canonpath($dir) eq $source or $dir eq "." or $dir eq "/"
canonpath($dir) eq $source $dir eq "." $dir eq "/"
Truth table0%0/4
A or B or C
A= canonpath($dir) eq $sourceB= $dir eq "."C= $dir eq "/"
ABCresult
1XX1
01X1
0011
0000
599 0 $dir = dirname($dir);
600 }
601 0 return;
602 }
603  
604 =head2 write_page
605  
606 The C<write_page> tool.
607  
608 =cut
609  
610 0 ▶sub write_page {
Subroutine write_page: not called CC=11 SCAR=48.8
Pod documented
611 0 my ($dapper, $args) = @_;
612  
613 0 $dapper->read_project();
614 0 my $file = source_path($dapper, $args->{source});
615  
616 0 my $front_matter = $args->{front_matter};
617 0 ▶ die "error: front_matter must be an object of page settings\n" unless ref $front_matter eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $front_matter eq "HASH" 0 0 0
618 0 ▶ my $body = defined $args->{body} ? $args->{body} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'body'} ? : 0 0 0
619 0 ▶ die "error: body must be text\n" if ref $body;
Branch: 1 branch
BranchTrueFalseTotal
if ref $body 0 0 0
620  
621 0 ▶ if (-e $file and not $args->{overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file and not $args->{"overwrite"}) 0 0 0
Condition0%0/3
-e $file and not $args->{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and not $args->{"overwrite"}
-e $file not $args->{"overwrite"}
Truth table0%0/3
A and not(B)
A= -e $fileB= not $args->{"overwrite"}
ABresult
0X0
100
111
622 0 return ({ written => JSON::false, error => "$file already exists; set overwrite to true to replace it" }, 1);
623 }
624  
625 0 ▶ if (my $schema = schema_for($dapper, $file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = schema_for($dapper, $file)) 0 0 0
626 0 my @problems = App::Dapper::Schema::validate($schema, $front_matter);
627 0 ▶ if (@problems) {
Branch: 1 branch
BranchTrueFalseTotal
if (@problems) 0 0 0
628 0 return ({ written => JSON::false, schema => $schema->{file}, problems => \@problems,
629 error => "The front matter does not match $schema->{file}, so the page was not written." }, 1);
630 }
631 }
632  
633 0 my $yaml = YAML::PP->new(boolean => 'JSON::PP')->dump_string($front_matter);
634 0 ▶ $yaml = "---\n$yaml" unless $yaml =~ /^---/;
Branch: 1 branch
BranchTrueFalseTotal
unless $yaml =~ /^---/ 0 0 0
635 0 ▶ $yaml .= "\n" unless $yaml =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $yaml =~ /\n\z/ 0 0 0
636 0 ▶ $body .= "\n" unless $body =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ /\n\z/ 0 0 0
637  
638 0 App::Dapper::Utils::write_file($file, "$yaml---\n\n$body");
639  
640 0 return { written => JSON::true, file => $file, note => 'Run check to find problems, or build to publish.' };
641 }
642  
643 =head2 rename_page
644  
645 The C<rename_page> tool.
646  
647 =cut
648  
649 0 ▶sub rename_page {
Subroutine rename_page: not called CC=11 SCAR=48.8
Pod documented
650 0 my ($dapper, $args) = @_;
651  
652 0 $dapper->read_project();
653 0 my $from = source_path($dapper, $args->{source});
654 0 my $to = source_path($dapper, $args->{new_source});
655 0 ▶ die "error: there is no file \"$from\"\n" unless -f $from;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $from 0 0 0
656 0 ▶ return ({ moved => JSON::false, error => "$to already exists" }, 1) if -e $to;
Branch: 1 branch
BranchTrueFalseTotal
if -e $to 0 0 0
657  
658 # The page must match the schema of the folder it is moving to
659 0 my $text = App::Dapper::Utils::read_file($from);
660 0 my ($front_matter) = App::Dapper::Utils::split_frontmatter($text, $from);
661 0 ▶ if (defined $front_matter and my $schema = schema_for($dapper, $to)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $front_matter and my $schema = schema_for($dapper, $to)) 0 0 0
Condition0%0/3
defined $front_matter and my $schema = schema_for($dapper, $to)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $front_matter and my $schema = schema_for($dapper, $to)
defined $front_matter my $schema = schema_for($dapper, $to)
Truth table0%0/3
A and B
A= defined $front_matterB= my $schema = schema_for($dapper, $to)
ABresult
0X0
100
111
662 0 my @problems = App::Dapper::Schema::validate($schema, $front_matter);
663 0 ▶ return ({ moved => JSON::false, schema => $schema->{file}, problems => \@problems,
Branch: 1 branch
BranchTrueFalseTotal
if @problems 0 0 0
664 error => "The page does not match $schema->{file}, so it was not moved." }, 1) if @problems;
665 }
666  
667 0 my $old_url = _url_of($dapper, $from);
668  
669 0 ▶ make_path(dirname($to)) unless -d dirname($to);
Branch: 1 branch
BranchTrueFalseTotal
unless -d dirname($to) 0 0 0
670 0 ▶ rename($from, $to) or die "error: could not move $from to $to: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
rename $from, $to or die "error: could not move $from to ${to}: $!\n" 0 0 0
671  
672 0 my $new_url = _url_of($dapper, $to);
673 0 my %result = (moved => JSON::true, from => $from, to => $to, old_url => $old_url, new_url => $new_url);
674  
675 0 ▶ if (defined $old_url and defined $new_url and $old_url ne $new_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old_url and defined $new_url and $old_url ne $new_url) 0 0 0
Condition0%0/6
defined $old_url and defined $new_url and $old_url ne $new_url
!ll&&!rl&&r
000
defined $old_url and defined $new_url
!ll&&!rl&&r
000
MC/DC0%0/3
defined $old_url and defined $new_url and $old_url ne $new_url
defined $old_url defined $new_url $old_url ne $new_url
Truth table0%0/4
A and B and C
A= defined $old_urlB= defined $new_urlC= $old_url ne $new_url
ABCresult
0XX0
10X0
1100
1111
676 0 add_redirect($dapper, $old_url, $new_url);
677 0 $result{redirect} = "$old_url -> $new_url (in " . redirects_file($dapper) . ")";
678 }
679  
680 0 $result{note} = 'Run check to find problems, or build to publish.';
681 0 return \%result;
682 }
683  
684 0 ▶sub _url_of {
Subroutine _url_of: not called CC=2 SCAR=17.9
685 0 my ($dapper, $file) = @_;
686  
687 0 _load($dapper);
688 0 my ($page) = grep { $_->{source} eq $file } @{$dapper->{site}->{pages}};
689 0 ▶ return $page ? $page->{url} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$page ? : 0 0 0
690 }
691  
692 =head2 redirects_file
693  
694 Takes a Dapper object and returns the path of C<_data/redirects.yml>.
695  
696 =cut
697  
698 0 ▶sub redirects_file {
Subroutine redirects_file: not called CC=1 SCAR=6.9
Pod documented
699 0 my ($dapper) = @_;
700 0 return catfile($dapper->{data_dir}, 'redirects.yml');
701 }
702  
703 =head2 add_redirect
704  
705 Takes a Dapper object, an old URL and a new one, and records the redirect in
706 C<_data/redirects.yml>. Redirects that pointed to the old URL are pointed at
707 the new one, so there are no chains.
708  
709 =cut
710  
711 0 ▶sub add_redirect {
Subroutine add_redirect: not called CC=5 SCAR=34.0
Pod documented
712 0 my ($dapper, $from, $to) = @_;
713  
714 0 my $file = redirects_file($dapper);
715 0 ▶ my $redirects = -f $file ? YAML::PP->new->load_file($file) : {};
Branch: 1 branch
BranchTrueFalseTotal
-f $file ? : 0 0 0
716 0 ▶ $redirects = {} unless ref $redirects eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $redirects eq "HASH" 0 0 0
717  
718 0 for my $old (keys %$redirects) {
719 0 ▶ $redirects->{$old} = $to if $redirects->{$old} eq $from;
Branch: 1 branch
BranchTrueFalseTotal
if $redirects->{$old} eq $from 0 0 0
720 }
721 0 $redirects->{$from} = $to;
722 0 delete $redirects->{$to};
723  
724 0 my $yaml = YAML::PP->new->dump_string($redirects);
725 0 $yaml =~ s/^---\n//;
726 0 App::Dapper::Utils::write_file($file,
727 "# Redirects from old URLs to new ones (written by Dapper when pages move; edit freely)\n$yaml");
728 }
729  
730 =head2 layout_name
731  
732 Takes a layout name from a client and returns it, or dies if it isn't a
733 plain name.
734  
735 =cut
736  
737 0 ▶sub layout_name {
Subroutine layout_name: not called CC=4 SCAR=30.0
Pod documented
738 0 my ($name) = @_;
739  
740 0 ▶ die "error: give the layout's name, e.g. post\n" unless defined $name and length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
741 0 $name =~ s/\.html?$//;
742 0 ▶ die "error: a layout name can only have letters, digits, - and _\n" unless $name =~ /^[A-Za-z0-9_-]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^[A-Za-z0-9_-]+$/ 0 0 0
743 0 return $name;
744 }
745  
746 =head2 read_layout
747  
748 The C<read_layout> tool.
749  
750 =cut
751  
752 0 ▶sub read_layout {
Subroutine read_layout: not called CC=2 SCAR=17.9
Pod documented
753 0 my ($dapper, $args) = @_;
754  
755 0 $dapper->read_project();
756 0 my $name = layout_name($args->{name});
757 0 my ($file) = grep { App::Dapper::Utils::filter_stem($_) eq $name } App::Dapper::Utils::read_dir($dapper->{layout});
758 0 ▶ die "error: there is no layout called \"$name\" in $dapper->{layout}\n" unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
759  
760 0 my $path = catfile($dapper->{layout}, $file);
761 0 return { name => $name, file => $path, content => App::Dapper::Utils::read_file($path) };
762 }
763  
764 =head2 write_layout
765  
766 The C<write_layout> tool.
767  
768 =cut
769  
770 0 ▶sub write_layout {
Subroutine write_layout: not called CC=14 SCAR=53.5
Pod documented
771 0 my ($dapper, $args) = @_;
772  
773 0 $dapper->read_project();
774 0 my $name = layout_name($args->{name});
775 0 my $content = $args->{content};
776 0 ▶ die "error: content must be text\n" unless defined $content and !ref $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content and not ref $content 0 0 0
Condition0%0/3
defined $content and not ref $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content and not ref $content
defined $content not ref $content
Truth table0%0/3
A and not(B)
A= defined $contentB= not ref $content
ABresult
0X0
100
111
777  
778 0 my ($existing) = grep { App::Dapper::Utils::filter_stem($_) eq $name } App::Dapper::Utils::read_dir($dapper->{layout});
779 0 ▶ my $path = catfile($dapper->{layout}, defined $existing ? $existing : "$name.html");
Branch: 1 branch
BranchTrueFalseTotal
defined $existing ? : 0 0 0
780 0 ▶ if (defined $existing and not $args->{overwrite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $existing and not $args->{"overwrite"}) 0 0 0
Condition0%0/3
defined $existing and not $args->{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $existing and not $args->{"overwrite"}
defined $existing not $args->{"overwrite"}
Truth table0%0/3
A and not(B)
A= defined $existingB= not $args->{"overwrite"}
ABresult
0X0
100
111
781 0 return ({ written => JSON::false, error => "$path already exists; set overwrite to true to replace it" }, 1);
782 }
783  
784 # Check the template before saving it
785 0 my ($front_matter, $body) = App::Dapper::Utils::split_frontmatter($content, $path);
786 0 ▶ $body = $content unless defined $front_matter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $front_matter 0 0 0
787 0 my $parsed = eval { Template::Alloy->new(INCLUDE_PATH => $dapper->{layout})->load_template(\$body); 1 };
788 0 ▶ if (not $parsed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parsed) 0 0 0
789 0 ▶ my $error = ref $@ && $@->can('as_string') ? $@->as_string : "$@";
Branch: 1 branch
BranchTrueFalseTotal
ref $@ && $@->can('as_string') ? : 0 0 0
Condition0%0/3
ref $@ and $@->can("as_string")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $@ and $@->can("as_string")
ref $@ $@->can("as_string")
Truth table0%0/3
A and B
A= ref $@B= $@->can("as_string")
ABresult
0X0
100
111
790 0 $error =~ s/\s+\z//;
791 0 return ({ written => JSON::false, error => "The layout has a template error, so it was not saved: $error" }, 1);
792 }
793 0 ▶ if (defined $front_matter and defined $front_matter->{layout}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $front_matter and defined $front_matter->{"layout"}) 0 0 0
Condition0%0/3
defined $front_matter and defined $front_matter->{"layout"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $front_matter and defined $front_matter->{"layout"}
defined $front_matter defined $front_matter->{"layout"}
Truth table0%0/3
A and B
A= defined $front_matterB= defined $front_matter->{"layout"}
ABresult
0X0
100
111
794 0 my $parent = $front_matter->{layout};
795 0 my ($found) = grep { App::Dapper::Utils::filter_stem($_) eq $parent } App::Dapper::Utils::read_dir($dapper->{layout});
796 0 ▶ return ({ written => JSON::false, error => "The layout wraps itself in \"$parent\", which does not exist, so it was not saved." }, 1)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $found 0 0 0
797 unless defined $found;
798 }
799  
800 0 ▶ $content .= "\n" unless $content =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /\n\z/ 0 0 0
801 0 App::Dapper::Utils::write_file($path, $content);
802 0 return { written => JSON::true, file => $path, note => 'Run check to find problems, or build to publish.' };
803 }
804  
805 =head2 build
806  
807 The C<build> tool.
808  
809 =cut
810  
811 0 ▶sub build {
Subroutine build: not called CC=1 SCAR=6.9
Pod documented
812 0 my ($dapper) = @_;
813  
814 0 local $dapper->{quiet} = 1;
815 0 $dapper->build();
816  
817 return {
818 built => JSON::true,
819 output => $dapper->{output},
820 0 pages => scalar @{$dapper->{site}->{pages}},
821 0 files => scalar keys %{$dapper->{written}},
822 };
823 }
824  
825 =head2 check
826  
827 The C<check> tool.
828  
829 =cut
830  
831 0 ▶sub check {
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
832 0 my ($dapper) = @_;
833  
834 0 return $dapper->check();
835 }
836  
837 32 1;
« lib/App/Dapper/Collections.pm ↑ Summary lib/App/Dapper/Init.pm »