| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This file is part of Markdown::Pod::Embed. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # Full license text is available at: | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # <http://dev.perl.org/licenses/> | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Getopt::Long qw(GetOptions); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Markdown::Pod::Embed; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $VERSION='1.011'; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 25 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 'inplace|i' => \$opt{'inplace'}, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'recursive|recurse|r' => \$opt{'recursive'}, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 'dry-run' => \$opt{'dry_run'}, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 'nobackup' => \$opt{'nobackup'}, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 'dialect=s' => \$opt{'dialect'}, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'extract-markdown|extract_markdown' => \$opt{'markdown'}, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 'extract-pod|extract_pod' => \$opt{'pod'}, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 'version' => \$opt{'version'}, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | 'help' => \$opt{'help'}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | ) or die "invalid options; use --help\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if ($opt{'help'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | print "Usage: markpod [--inplace] [--recursive] [--dry-run] [--nobackup] FILE...\n"; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | print " markpod --extract-markdown|--extract-pod FILE\n"; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | if ($opt{'version'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | print "markpod $VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | die "supply a file or directory\n" unless @ARGV; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | die "choose one extraction mode\n" if $opt{'markdown'} && $opt{'pod'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt{"markdown"} and $opt{"pod"}
MC/DC0%0/2
$opt{"markdown"} and $opt{"pod"}
$opt{"markdown"}
$opt{"pod"}
Truth table33%1/3
A and B
A= $opt{"markdown"}B= $opt{"pod"}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | die "extraction cannot update files\n" if $opt{'inplace'} && ($opt{'markdown'} || $opt{'pod'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$opt{"inplace"} and $opt{"markdown"} || $opt{"pod"}
$opt{"markdown"} or $opt{"pod"}
MC/DC0%0/3
$opt{"inplace"} and $opt{"markdown"} || $opt{"pod"}
$opt{"inplace"}
$opt{"markdown"}
$opt{"pod"}
Truth table25%1/4
A and B or C
A= $opt{"inplace"}B= $opt{"markdown"}C= $opt{"pod"}
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | die "directories require --recursive\n" if !$opt{'recursive'} && grep { -d $_ } @ARGV; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $opt{"recursive"} and grep {-d $_;} @ARGV
MC/DC0%0/2
not $opt{"recursive"} and grep {-d $_;} @ARGV
not $opt{"recursive"}
grep {-d $_;} @ARGV
Truth table33%1/3
not(A) and B
A= not $opt{"recursive"}B= grep {-d $_;} @ARGV
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my $file_ar=Markdown::Pod::Embed->discover(@ARGV); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | delete $opt{'dialect'} unless defined $opt{'dialect'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $processor_or=Markdown::Pod::Embed->new(\%opt); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | foreach my $fn (@{$file_ar}) { | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $changed=$processor_or->process($fn); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | next unless defined $changed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ($opt{'dry_run'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | print "$fn: ", ($changed ? 'would update' : 'unchanged'), "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | elsif ($opt{'markdown'}) { print $processor_or->markdown() } | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | elsif ($opt{'pod'}) { print $processor_or->pod() } | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | elsif ($opt{'inplace'}) { $processor_or->markpod_inplace_update($fn) if $changed } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | else { print $processor_or->ppi_doc_or()->serialize() } | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =begin markdown | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # NAME | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | markpod - merge Markdown documentation into Perl files | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | `markpod --inplace --recursive lib bin` updates discovered source files. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | `--dry-run` reports intended changes without writing. `--nobackup` suppresses | ||||||||||||||||||||||||||||||||||||||||||
| 75 | backup files. Without `--inplace`, complete transformed source is printed. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | Use `--extract-markdown FILE` or `--extract-pod FILE` to print documentation | ||||||||||||||||||||||||||||||||||||||||||
| 78 | only. `--dialect GitHub` selects the Markdown::Pod dialect. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | `--version` prints the installed program version. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | Supply files explicitly, or use `--recursive` with directories. Unsupported | ||||||||||||||||||||||||||||||||||||||||||
| 83 | options and failed operations exit nonzero. A file with no Markdown source is | ||||||||||||||||||||||||||||||||||||||||||
| 84 | skipped. See Markdown::Pod::Embed for source precedence and preservation rules. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | Andrew Speer <andrew.speer@isolutions.com.au> | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # LICENSE and COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | This file is part of Markdown::Pod::Embed. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 97 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | Full license text is available at: | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | <http://dev.perl.org/licenses/> | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =end markdown | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | markpod - merge Markdown documentation into Perl files | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | C<markpod --inplace --recursive lib bin> updates discovered source files. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | C<--dry-run> reports intended changes without writing. C<--nobackup> suppresses | ||||||||||||||||||||||||||||||||||||||||||
| 116 | backup files. Without C<--inplace>, complete transformed source is printed. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Use C<--extract-markdown FILE> or C<--extract-pod FILE> to print documentation | ||||||||||||||||||||||||||||||||||||||||||
| 119 | only. C<--dialect GitHub> selects the Markdown::Pod dialect. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | C<--version> prints the installed program version. | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | Supply files explicitly, or use C<--recursive> with directories. Unsupported | ||||||||||||||||||||||||||||||||||||||||||
| 124 | options and failed operations exit nonzero. A file with no Markdown source is | ||||||||||||||||||||||||||||||||||||||||||
| 125 | skipped. See Markdown::Pod::Embed for source precedence and preservation rules. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | Andrew Speer L<mailto:andrew.speer@isolutions.com.au> | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | This software is copyright (c) 2026 by Andrew Speer. It may be distributed | ||||||||||||||||||||||||||||||||||||||||||
| 136 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||||||||||