bin/dapper

filter: Statementstmt 79.1% 76 / 96 Branchbran 65.3% 17 / 26 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 82.6% 19 / 23 Podpod n/a totaltotal 78.0% 117 / 150 CC 6 SCAR 11.9
CC
6
Cov
77%
serve
12.0
check
9.3
help
2.1
CRAP 3.3
« lib/App/Dapper/Utils.pm ↑ Summary lib/App/Dapper/Markdown.pm »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 dapper - A publishing tool for static websites.
6  
7 =cut
8  
9 127 ▶use open ':std', ':encoding(UTF-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 127 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 127 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 127 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 127 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 127 ▶use lib "$FindBin::Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 127 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 127 ▶use Getopt::Long qw(:config bundling no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 127 ▶use App::Dapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 127 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 127 my $SOURCE = undef;
24 127 my $OUTPUT = undef;
25 127 my $LAYOUT = undef;
26 127 my $CONFIG = undef;
27 127 my $PORT = 8000;
28 127 my $QUIET = 0;
29 127 my $HELP = 0;
30 127 my $VERSION = 0;
31 127 my $JSON = 0;
32 127 my $TEMPLATE = undef;
33 127 my $DIRECTORY = undef;
34 127 my $DRY_RUN = 0;
35 127 my $FORCE = 0;
36 127 my $NO_BUILD = 0;
37 127 my $DRAFTS = 0;
38 127 my $TO = undef;
39  
40 =head1 SYNOPSIS
41  
42 dapper [options] <command>
43  
44 # Initialize the current directory with a fresh skeleton of a site
45 $ dapper init
46  
47 # ...or with a complete starter blog
48 $ dapper init --template blog
49  
50 # ...or a portfolio, business or docs site, or a theme from git
51 $ dapper init --template business
52 $ dapper init --template https://github.com/someone/dapper-theme.git
53  
54 # List the starter templates
55 $ dapper templates
56  
57 # Build the site
58 $ dapper build
59  
60 # ...including drafts and pages dated in the future
61 $ dapper build --drafts
62  
63 # Build the site, then serve it locally at http://localhost:8000,
64 # rebuilding whenever a file changes
65 $ dapper serve
66  
67 # Rebuild the site whenever a file (source, layout, config) changes
68 $ dapper watch
69  
70 # Check the site for problems (add --json for a machine-readable report)
71 $ dapper check
72  
73 # Build, check and publish the site (to S3, GitHub Pages, or a command)
74 $ dapper deploy
75 $ dapper deploy --dry-run
76 $ dapper deploy s3 # with several targets, name one
77  
78 # Let AI assistants work on the site over MCP
79 $ dapper -C /path/to/site mcp
80  
81 # Write or update AGENTS.md, which explains the project to AI coding agents
82 $ dapper agents
83  
84 # Bring in the pages of a WordPress, Jekyll, Hugo or Medium site
85 $ dapper import wordpress export.xml
86 $ dapper import jekyll ../old-site --dry-run
87  
88 # Get help on usage and switches
89 $ dapper -h
90  
91 # Print the version
92 $ dapper -v
93  
94 =head1 DESCRIPTION
95  
96 B<Dapper> transforms simple text files into static websites. Source files
97 (Markdown with YAML front matter) are combined with layout templates and
98 written to an output directory.
99  
100 See L<App::Dapper> or the README at L<https://github.com/markdbenson/dapper>
101 for the full documentation: the project file, source files, layouts,
102 variables, filters and deployment.
103  
104 =head1 OPTIONS
105  
106 =over 4
107  
108 =item B<-s>, B<--source>=I<source directory>
109  
110 Specify the directory containing source files to process. If this command line option is not present, it defaults to the C<source> setting in the config file, or "_source".
111  
112 =item B<-o>, B<--output>=I<output directory>
113  
114 Specify the directory to place the output files in. If this command line option is not present, it defaults to the C<output> setting in the config file, or "_output".
115  
116 =item B<-l>, B<--layout>=I<layout directory>
117  
118 Specify the directory containing layout files. If this command line option is not present, it defaults to the C<layout> setting in the config file, or "_layout".
119  
120 =item B<-c>, B<--config>=I<config file>
121  
122 Specify the config file name to use. If this command line option is not present, it defaults to "_config.yml".
123  
124 =item B<-p>, B<--port>=I<port>
125  
126 Specify the port to use for the serve command. This option is only used for the serve command. If this command line option is not present, it defaults to "8000".
127  
128 =item B<-q>, B<--quiet>
129  
130 Only print errors.
131  
132 =item B<-C>, B<--directory>=I<directory>
133  
134 Run in this directory instead of the current one.
135  
136 =item B<-t>, B<--template>=I<name>
137  
138 For the init command: the starter to create, a built-in template (see
139 C<dapper templates>), a directory, or a git URL.
140  
141 =item B<--dry-run>, B<--force>, B<--no-build>
142  
143 For the deploy command: show what would happen without publishing; deploy even
144 if C<dapper check> finds errors; deploy the output directory without building
145 it first. C<--dry-run> also works for the import command.
146  
147 =item B<--to>=I<directory>
148  
149 For the import command: the directory in the source directory that imported
150 posts go in (default: C<blog>).
151  
152 =item B<--drafts>
153  
154 For the build, watch and check commands: include drafts and pages dated in
155 the future, which are otherwise held back. C<dapper serve> always includes
156 them; C<dapper deploy> never does.
157  
158 =item B<--json>
159  
160 For the check command: print the report as JSON.
161  
162 =item B<-h>, B<--help>
163  
164 Get help on available commands and options.
165  
166 =item B<-v>, B<--version>
167  
168 Print the version and exit.
169  
170 =back
171  
172 =cut
173  
174 91 ▶sub dapper {
Subroutine dapper: called CC=1 SCAR=4.1
175 91 my $d = App::Dapper->new($SOURCE, $OUTPUT, $LAYOUT, $CONFIG);
176 0 $d->{quiet} = $QUIET;
177 0 $d->{template} = $TEMPLATE;
178 0 $d->{drafts} = $DRAFTS;
179 0 return $d;
180 }
181  
182 22 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
183 22 dapper()->init();
184 }
185  
186 26 ▶sub build {
Subroutine build: called CC=1 SCAR=0.0
187 26 dapper()->build();
188 }
189  
190 0 ▶sub watch {
Subroutine watch: not called CC=1 SCAR=6.9
191 0 dapper()->watch();
192 }
193  
194 7 ▶sub check {
Subroutine check: called CC=3 SCAR=22.3
195 7 my $report = dapper()->check();
196 0 ▶ if ($JSON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JSON) { } 0 0 0
197 0 print JSON->new->canonical->pretty->encode($report);
198 }
199 else {
200 0 print App::Dapper::Check::text($report);
201 }
202 0 ▶ exit($report->{ok} ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$report->{'ok'} ? : 0 0 0
203 }
204  
205 0 ▶sub serve {
Subroutine serve: not called CC=3 SCAR=24.8
206 0 my $pid = fork();
207 0 ▶ die "error: could not fork: $!\n" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
208 0 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 0 0 0
209 0 my $d = dapper();
210 0 $d->{live_reload} = 1;
211 0 $d->{drafts} = 1;
212 0 $d->watch();
213 0 exit(0);
214 }
215 0 dapper()->serve($PORT);
216 }
217  
218 25 ▶sub help {
Subroutine help: called CC=2 SCAR=7.2
219 25 my ($status) = @_;
220 25 ▶ pod2usage({ -verbose => 1, -exitval => defined $status ? $status : 0 });
Branch: 1 branch
BranchTrueFalseTotal
defined $status ? : 25 0 25
221 }
222  
223 6 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
224 6 print "Dapper version $App::Dapper::VERSION\n";
225 6 exit(0);
226 }
227  
228 127 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("s|source=s", \$SOURCE, "o|output=s", \$OUTPUT, "l|layout=s", \$LAYOUT, "c|config=s", \$CONFIG, "p|port=i", \$PORT, "q|quiet", \$QUIET, "h|help", \$HELP, "v|version", \$VERSION, "json", \$JSON, "t|template=s", \$TEMPLATE, "C|directory=s", \$DIRECTORY, "dry-run", \$DRY_RUN, "force", \$FORCE, "no-build", \$NO_BUILD, "drafts", \$DRAFTS, "to=s", \$TO) or help(2) 114 13 127
229 's|source=s' => \$SOURCE,
230 'o|output=s' => \$OUTPUT,
231 'l|layout=s' => \$LAYOUT,
232 'c|config=s' => \$CONFIG,
233 'p|port=i' => \$PORT,
234 'q|quiet' => \$QUIET,
235 'h|help' => \$HELP,
236 'v|version' => \$VERSION,
237 'json' => \$JSON,
238 't|template=s' => \$TEMPLATE,
239 'C|directory=s' => \$DIRECTORY,
240 'dry-run' => \$DRY_RUN,
241 'force' => \$FORCE,
242 'no-build' => \$NO_BUILD,
243 'drafts' => \$DRAFTS,
244 'to=s' => \$TO,
245 ) or help(2);
246  
247 114 ▶help(0) if $HELP;
Branch: 1 branch
BranchTrueFalseTotal
if $HELP 4 110 114
248 110 ▶version() if $VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if $VERSION 6 104 110
249  
250 104 ▶if (defined $DIRECTORY) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $DIRECTORY) 6 98 104
251 6 ▶ chdir $DIRECTORY or do { print STDERR "error: could not change to \"$DIRECTORY\": $!\n"; exit(1) };
Branch: 1 branch
BranchTrueFalseTotal
chdir $DIRECTORY or do { print STDERR qq[error: could not change to "$DIRECTORY": $!\n]; exit 1 } 3 3 6
252 }
253  
254 101 my $COMMAND = shift @ARGV;
255 101 ▶help(0) if not defined $COMMAND or $COMMAND eq 'help';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $COMMAND or $COMMAND eq "help" 3 98 101
Condition100%3/3
not defined $COMMAND or $COMMAND eq "help"
l!l&&r!l&&!r
1298
MC/DC100%2/2
not defined $COMMAND or $COMMAND eq "help"
not defined $COMMAND $COMMAND eq "help"
Truth table100%3/3
not(A) or B
A= not defined $COMMANDB= $COMMAND eq "help"
ABresult
1X1
011
000
256  
257 my $switch = {
258 'init' => \&init,
259 'build' => \&build,
260 'serve' => \&serve,
261 'watch' => \&watch,
262 'check' => \&check,
263 24 ▶ 'deploy' => sub { dapper()->deploy(shift(@ARGV), dry_run => $DRY_RUN, force => $FORCE, no_build => $NO_BUILD) },
Subroutine __ANON__: called CC=1 SCAR=0.0
264 0 ▶ 'mcp' => sub { dapper()->mcp() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
265 0 ▶ 'agents' => sub { dapper()->agents() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
266 12 ▶ 'import' => sub { dapper()->import_from(shift(@ARGV), shift(@ARGV), to => $TO, dry_run => $DRY_RUN) },
Subroutine __ANON__: called CC=1 SCAR=0.0
267 2 ▶ 'templates' => sub { print map { sprintf("%-10s %s\n", $_, App::Dapper::Init::description($_)) } App::Dapper::Init::templates() },
Subroutine __ANON__: called CC=1 SCAR=0.0
268 98 };
269  
270 98 ▶if (not $switch->{$COMMAND}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($switch->{$COMMAND}) 5 93 98
271 5 print STDERR "error: unknown command \"$COMMAND\"\n\n";
272 5 help(2);
273 }
274  
275 93 ▶eval { $switch->{$COMMAND}->(); 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $switch->{$COMMAND}->(); 1 } } or do { print STDERR $@; exit 1 } 2 91 93
276 91 print STDERR $@;
277 91 exit(1);
278 };
279  
280 2 exit(0);
281  
282 =head1 AUTHOR
283  
284 Mark Benson, C<< <mark at jayber.org> >>
285  
286 =head1 BUGS
287  
288 Please report any bugs or feature requests at
289 L<https://github.com/markdbenson/dapper/issues>.
290  
291 =head1 LICENSE AND COPYRIGHT
292  
293 The MIT License (MIT)
294  
295 Copyright (c) 2002-2026 Mark Benson
296  
297 See L<App::Dapper> for the full license text.
298  
299 =cut
« lib/App/Dapper/Utils.pm ↑ Summary lib/App/Dapper/Markdown.pm »