| 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.012'; | |||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||