bin/dapper

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