| 1 | # | ||||||||||||
| 2 | # This file is part of ASPEER::MakeMaker::Markdown::Pod. | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||
| 5 | # | ||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 8 | # | ||||||||||||
| 9 | # Full license text is available at: | ||||||||||||
| 10 | # | ||||||||||||
| 11 | # <http://dev.perl.org/licenses/> | ||||||||||||
| 12 | # | ||||||||||||
| 13 | |||||||||||||
| 14 | # | ||||||||||||
| 15 | |||||||||||||
| 16 | |||||||||||||
| 17 | # Pragma | ||||||||||||
| 18 | # | ||||||||||||
| 19 | package ASPEER::MakeMaker::Markdown::Pod::Constant; | ||||||||||||
| 20 | 2 | ▶ | use strict qw(vars); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 2 | ▶ | use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT %Constant); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | # Modules we need | ||||||||||||
| 26 | # | ||||||||||||
| 27 | 2 | ▶ | use File::Spec; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | # Version information | ||||||||||||
| 31 | # | ||||||||||||
| 32 | 2 | $VERSION='1.012'; | |||||||||||
| 33 | |||||||||||||
| 34 | |||||||||||||
| 35 | # Get module file name and path, derive name of file to store local constants | ||||||||||||
| 36 | # | ||||||||||||
| 37 | 2 | ▶ | use Cwd qw(abs_path); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 2 | my $local_fn=abs_path(__FILE__) . '.local'; | |||||||||||
| 39 | |||||||||||||
| 40 | |||||||||||||
| 41 | # Find file in path | ||||||||||||
| 42 | # | ||||||||||||
| 43 | 2 | ▶ | sub bin_find { | ||||||||||
|
Subroutine
bin_find: called CC=8 SCAR=21.8
Pod
documented
| |||||||||||||
| 44 | |||||||||||||
| 45 | |||||||||||||
| 46 | # Find a binary file | ||||||||||||
| 47 | # | ||||||||||||
| 48 | 2 | my @bin_fn=@_; | |||||||||||
| 49 | 2 | my $bin_fn; | |||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | # Find the bin file/files if given array ref. If not supplied as array ref | ||||||||||||
| 53 | # convert. | ||||||||||||
| 54 | # | ||||||||||||
| 55 | 2 | my @dir=grep {-d $_} split(/:|;/, $ENV{'PATH'}); | |||||||||||
| 56 | 2 | my %dir=map {$_ => 1} @dir; | |||||||||||
| 57 | 2 | DIR: foreach my $dir (@dir) { | |||||||||||
| 58 | 20 | ▶ | next unless delete $dir{$dir}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 16 | ▶ | next unless -d $dir; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 16 | foreach my $bin (@bin_fn) { | |||||||||||
| 61 | 32 | ▶ | if (-f File::Spec->catfile($dir, $bin)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 0 | $bin_fn=File::Spec->catfile($dir, $bin); | |||||||||||
| 63 | 0 | last DIR; | |||||||||||
| 64 | } | ||||||||||||
| 65 | } | ||||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | |||||||||||||
| 69 | # Normalize fn | ||||||||||||
| 70 | # | ||||||||||||
| 71 | 2 | ▶ | $bin_fn=File::Spec->canonpath($bin_fn) if $bin_fn; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | # Return | ||||||||||||
| 75 | # | ||||||||||||
| 76 | 2 | ▶ | return $bin_fn || ''; | ||||||||||
|
Condition50%1/2
$bin_fn || ''
MC/DC0%0/1
$bin_fn || ''
$bin_fn
Truth table50%1/2
A
A= $bin_fn
| |||||||||||||
| 77 | |||||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | |||||||||||||
| 81 | |||||||||||||
| 82 | # Hash of constants | ||||||||||||
| 83 | # | ||||||||||||
| 84 | %Constant=( | ||||||||||||
| 85 | |||||||||||||
| 86 | OPTION_HR => { | ||||||||||||
| 87 | dialect => 'GitHub', | ||||||||||||
| 88 | }, | ||||||||||||
| 89 | |||||||||||||
| 90 | |||||||||||||
| 91 | PANDOC_EXE => &bin_find(qw(pandoc pandoc.exe)), | ||||||||||||
| 92 | |||||||||||||
| 93 | 0 | ▶ | PANDOC_CMD_MD2TEXT_CR => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 94 | return [ | ||||||||||||
| 95 | 0 | shift(), # PANDOC_EXE | |||||||||||
| 96 | '-fmarkdown_github', # from markdown (github dialect) | ||||||||||||
| 97 | '-tplain', # to plaintext | ||||||||||||
| 98 | shift(), # File name | ||||||||||||
| 99 | ] | ||||||||||||
| 100 | }, | ||||||||||||
| 101 | |||||||||||||
| 102 | # Local constants override anything above | ||||||||||||
| 103 | # | ||||||||||||
| 104 | 2 | ▶ | %{do($local_fn) || {}}, | ||||||||||
|
Condition50%1/2
do $local_fn || {}
MC/DC0%0/1
do $local_fn || {}
do $local_fn
Truth table50%1/2
A
A= do $local_fn
| |||||||||||||
| 105 | 2 | ▶ | %{do(glob(sprintf('~/.%s.local', __PACKAGE__))) || {}} # || {} avoids warning | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Condition50%1/2
do (glob('~/.ASPEER::MakeMaker::Markdown::Pod::Constant.local')) || {}
MC/DC0%0/1
do (glob('~/.ASPEER::MakeMaker::Markdown::Pod::Constant.local')) || {}
do (glob('~/.ASPEER::MakeMaker::Markdown::Pod::Constant.local'))
Truth table50%1/2
A
A= do (glob('~/.ASPEER::MakeMaker::Markdown::Pod::Constant.local'))
| |||||||||||||
| 106 | |||||||||||||
| 107 | ); | ||||||||||||
| 108 | |||||||||||||
| 109 | |||||||||||||
| 110 | # Export constants to namespace, place in export tags | ||||||||||||
| 111 | # | ||||||||||||
| 112 | 2 | require Exporter; | |||||||||||
| 113 | 2 | @ISA=qw(Exporter); | |||||||||||
| 114 | 2 | foreach (keys %Constant) {${$_}=$Constant{$_}} | |||||||||||
| 115 | 2 | @EXPORT=map {'$' . $_} keys %Constant; | |||||||||||
| 116 | 2 | @EXPORT_OK=@EXPORT; | |||||||||||
| 117 | 2 | %EXPORT_TAGS=(all => [@EXPORT_OK]); | |||||||||||
| 118 | 2 | $_=\%Constant; | |||||||||||
| 119 | __END__ | ||||||||||||
| 120 | |||||||||||||
| 121 | =begin markdown | ||||||||||||
| 122 | |||||||||||||
| 123 | # NAME | ||||||||||||
| 124 | |||||||||||||
| 125 | ASPEER::MakeMaker::Markdown::Pod::Constant - constants for ASPEER::MakeMaker::Markdown::Pod | ||||||||||||
| 126 | |||||||||||||
| 127 | # SYNOPSIS | ||||||||||||
| 128 | |||||||||||||
| 129 | ```perl | ||||||||||||
| 130 | use ASPEER::MakeMaker::Markdown::Pod::Constant; | ||||||||||||
| 131 | |||||||||||||
| 132 | my $default_dialect = $OPTION_HR->{dialect}; | ||||||||||||
| 133 | my $pandoc = $PANDOC_EXE; | ||||||||||||
| 134 | my $cmd = $PANDOC_CMD_MD2TEXT_CR->($pandoc, '-'); | ||||||||||||
| 135 | ``` | ||||||||||||
| 136 | |||||||||||||
| 137 | # DESCRIPTION | ||||||||||||
| 138 | |||||||||||||
| 139 | `ASPEER::MakeMaker::Markdown::Pod::Constant` defines exported constants used by the core | ||||||||||||
| 140 | processor and command-line tool. | ||||||||||||
| 141 | |||||||||||||
| 142 | The constants are stored in `%Constant`, exported as package variables, and can | ||||||||||||
| 143 | be overridden by local configuration files loaded at compile time. | ||||||||||||
| 144 | |||||||||||||
| 145 | # CONSTANTS | ||||||||||||
| 146 | |||||||||||||
| 147 | `$OPTION_HR` | ||||||||||||
| 148 | : Default processor options. The current default Markdown dialect is `GitHub`. | ||||||||||||
| 149 | |||||||||||||
| 150 | `$PANDOC_EXE` | ||||||||||||
| 151 | : Path to `pandoc` discovered from `PATH`, or an empty string when `pandoc` is | ||||||||||||
| 152 | not available. | ||||||||||||
| 153 | |||||||||||||
| 154 | `$PANDOC_CMD_MD2TEXT_CR` | ||||||||||||
| 155 | : Code reference that builds the `pandoc` command used to render Markdown to | ||||||||||||
| 156 | plain text for README generation. | ||||||||||||
| 157 | |||||||||||||
| 158 | # FUNCTIONS | ||||||||||||
| 159 | |||||||||||||
| 160 | ## bin_find | ||||||||||||
| 161 | |||||||||||||
| 162 | ```perl | ||||||||||||
| 163 | my $path = ASPEER::MakeMaker::Markdown::Pod::Constant::bin_find(qw(pandoc pandoc.exe)); | ||||||||||||
| 164 | ``` | ||||||||||||
| 165 | |||||||||||||
| 166 | Searches `PATH` for the first executable-like file matching one of the supplied | ||||||||||||
| 167 | names and returns a canonical path. If no candidate is found, it returns an | ||||||||||||
| 168 | empty string. | ||||||||||||
| 169 | |||||||||||||
| 170 | # LOCAL OVERRIDES | ||||||||||||
| 171 | |||||||||||||
| 172 | Local constants can be overridden by files loaded from: | ||||||||||||
| 173 | |||||||||||||
| 174 | ```text | ||||||||||||
| 175 | lib/ASPEER/MakeMaker/Markdown/Pod/Constant.pm.local | ||||||||||||
| 176 | ~/.ASPEER::MakeMaker::Markdown::Pod::Constant.local | ||||||||||||
| 177 | ``` | ||||||||||||
| 178 | |||||||||||||
| 179 | Those files are expected to return a hash reference suitable for merging into | ||||||||||||
| 180 | `%Constant`. | ||||||||||||
| 181 | |||||||||||||
| 182 | # SEE ALSO | ||||||||||||
| 183 | |||||||||||||
| 184 | `ASPEER::MakeMaker::Markdown::Pod` | ||||||||||||
| 185 | |||||||||||||
| 186 | # AUTHOR | ||||||||||||
| 187 | |||||||||||||
| 188 | Andrew Speer <andrew.speer@isolutions.com.au> | ||||||||||||
| 189 | |||||||||||||
| 190 | # LICENSE and COPYRIGHT | ||||||||||||
| 191 | |||||||||||||
| 192 | This file is part of ASPEER::MakeMaker::Markdown::Pod. | ||||||||||||
| 193 | |||||||||||||
| 194 | This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||
| 195 | |||||||||||||
| 196 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 197 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 198 | |||||||||||||
| 199 | Full license text is available at: | ||||||||||||
| 200 | |||||||||||||
| 201 | <http://dev.perl.org/licenses/> | ||||||||||||
| 202 | |||||||||||||
| 203 | |||||||||||||
| 204 | =end markdown | ||||||||||||
| 205 | |||||||||||||
| 206 | |||||||||||||
| 207 | =head1 NAME | ||||||||||||
| 208 | |||||||||||||
| 209 | ASPEER::MakeMaker::Markdown::Pod::Constant - constants for ASPEER::MakeMaker::Markdown::Pod | ||||||||||||
| 210 | |||||||||||||
| 211 | |||||||||||||
| 212 | =head1 SYNOPSIS | ||||||||||||
| 213 | |||||||||||||
| 214 | |||||||||||||
| 215 | use ASPEER::MakeMaker::Markdown::Pod::Constant; | ||||||||||||
| 216 | |||||||||||||
| 217 | my $default_dialect = $OPTION_HR->{dialect}; | ||||||||||||
| 218 | my $pandoc = $PANDOC_EXE; | ||||||||||||
| 219 | my $cmd = $PANDOC_CMD_MD2TEXT_CR->($pandoc, '-'); | ||||||||||||
| 220 | |||||||||||||
| 221 | =head1 DESCRIPTION | ||||||||||||
| 222 | |||||||||||||
| 223 | C<ASPEER::MakeMaker::Markdown::Pod::Constant> defines exported constants used by the core | ||||||||||||
| 224 | processor and command-line tool. | ||||||||||||
| 225 | |||||||||||||
| 226 | The constants are stored in C<%Constant>, exported as package variables, and can | ||||||||||||
| 227 | be overridden by local configuration files loaded at compile time. | ||||||||||||
| 228 | |||||||||||||
| 229 | |||||||||||||
| 230 | =head1 CONSTANTS | ||||||||||||
| 231 | |||||||||||||
| 232 | C<$OPTION_HR> | ||||||||||||
| 233 | : Default processor options. The current default Markdown dialect is C<GitHub>. | ||||||||||||
| 234 | |||||||||||||
| 235 | C<$PANDOC_EXE> | ||||||||||||
| 236 | : Path to C<pandoc> discovered from C<PATH>, or an empty string when C<pandoc> is | ||||||||||||
| 237 | not available. | ||||||||||||
| 238 | |||||||||||||
| 239 | C<$PANDOC_CMD_MD2TEXT_CR> | ||||||||||||
| 240 | : Code reference that builds the C<pandoc> command used to render Markdown to | ||||||||||||
| 241 | plain text for README generation. | ||||||||||||
| 242 | |||||||||||||
| 243 | |||||||||||||
| 244 | =head1 FUNCTIONS | ||||||||||||
| 245 | |||||||||||||
| 246 | |||||||||||||
| 247 | =head2 bin_find | ||||||||||||
| 248 | |||||||||||||
| 249 | |||||||||||||
| 250 | my $path = ASPEER::MakeMaker::Markdown::Pod::Constant::bin_find(qw(pandoc pandoc.exe)); | ||||||||||||
| 251 | Searches C<PATH> for the first executable-like file matching one of the supplied | ||||||||||||
| 252 | names and returns a canonical path. If no candidate is found, it returns an | ||||||||||||
| 253 | empty string. | ||||||||||||
| 254 | |||||||||||||
| 255 | |||||||||||||
| 256 | =head1 LOCAL OVERRIDES | ||||||||||||
| 257 | |||||||||||||
| 258 | Local constants can be overridden by files loaded from: | ||||||||||||
| 259 | |||||||||||||
| 260 | |||||||||||||
| 261 | lib/ASPEER/MakeMaker/Markdown/Pod/Constant.pm.local | ||||||||||||
| 262 | ~/.ASPEER::MakeMaker::Markdown::Pod::Constant.local | ||||||||||||
| 263 | Those files are expected to return a hash reference suitable for merging into | ||||||||||||
| 264 | C<%Constant>. | ||||||||||||
| 265 | |||||||||||||
| 266 | |||||||||||||
| 267 | =head1 SEE ALSO | ||||||||||||
| 268 | |||||||||||||
| 269 | C<ASPEER::MakeMaker::Markdown::Pod> | ||||||||||||
| 270 | |||||||||||||
| 271 | |||||||||||||
| 272 | =head1 AUTHOR | ||||||||||||
| 273 | |||||||||||||
| 274 | Andrew Speer L<mailto:andrew.speer@isolutions.com.au> | ||||||||||||
| 275 | |||||||||||||
| 276 | |||||||||||||
| 277 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 278 | |||||||||||||
| 279 | This file is part of ASPEER::MakeMaker::Markdown::Pod. | ||||||||||||
| 280 | |||||||||||||
| 281 | This software is copyright (c) 2026 by Andrew Speer | ||||||||||||
| 282 | L<mailto:andrew.speer@isolutions.com.au>. | ||||||||||||
| 283 | |||||||||||||
| 284 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 285 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 286 | |||||||||||||
| 287 | Full license text is available at: | ||||||||||||
| 288 | |||||||||||||
| 289 | L<http://dev.perl.org/licenses/> | ||||||||||||
| 290 | |||||||||||||
| 291 | =cut | ||||||||||||