« lib/ASPEER/MakeMaker/Markdown/Pod/MM.pm
↑ Summary
blib/lib/ASPEER/MakeMaker/Markdown/Pod/MM/Constant.pm »
| 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.013'; | |||||||||||
| 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__ | ||||||||||||