ASPEER-MakeMaker-Markdown-Pod

 view release on metacpan or  search on metacpan

lib/ASPEER/MakeMaker/Markdown/Pod/Constant.pm  view on Meta::CPAN


    #  Find a binary file
    #
    my @bin_fn=@_;
    my $bin_fn;


    #  Find the bin file/files if given array ref. If not supplied as array ref
    #  convert.
    #
    my @dir=grep {-d $_} split(/:|;/, $ENV{'PATH'});
    my %dir=map  {$_ => 1} @dir;
    DIR: foreach my $dir (@dir) {
        next unless delete $dir{$dir};
        next unless -d $dir;
        foreach my $bin (@bin_fn) {
            if (-f File::Spec->catfile($dir, $bin)) {
                $bin_fn=File::Spec->catfile($dir, $bin);
                last DIR;
            }
        }
    }


    #  Normalize fn
    #
    $bin_fn=File::Spec->canonpath($bin_fn) if $bin_fn;


    #  Return
    #
    return $bin_fn || '';

}



#  Hash of constants
#
%Constant=(

    OPTION_HR => {
        dialect => 'GitHub',
    },


    PANDOC_EXE => &bin_find(qw(pandoc pandoc.exe)),

    PANDOC_CMD_MD2TEXT_CR => sub {
        return [
            shift(),                # PANDOC_EXE
            '-fmarkdown_github',    # from markdown (github dialect)
            '-tplain',              # to plaintext
            shift(),                # File name
        ]
    },

    #  Local constants override anything above
    #
    %{do($local_fn) || {}},
    %{do(glob(sprintf('~/.%s.local', __PACKAGE__))) || {}}    # || {} avoids warning

);


#  Export constants to namespace, place in export tags
#
require Exporter;
@ISA=qw(Exporter);
foreach (keys %Constant) {${$_}=$Constant{$_}}
@EXPORT=map {'$' . $_} keys %Constant;
@EXPORT_OK=@EXPORT;
%EXPORT_TAGS=(all => [@EXPORT_OK]);
$_=\%Constant;
__END__

=begin markdown

# NAME

ASPEER::MakeMaker::Markdown::Pod::Constant - constants for ASPEER::MakeMaker::Markdown::Pod

# SYNOPSIS

```perl
use ASPEER::MakeMaker::Markdown::Pod::Constant;

my $default_dialect = $OPTION_HR->{dialect};
my $pandoc          = $PANDOC_EXE;
my $cmd             = $PANDOC_CMD_MD2TEXT_CR->($pandoc, '-');
```

# DESCRIPTION

`ASPEER::MakeMaker::Markdown::Pod::Constant` defines exported constants used by the core
processor and command-line tool.

The constants are stored in `%Constant`, exported as package variables, and can
be overridden by local configuration files loaded at compile time.

# CONSTANTS

`$OPTION_HR`
: Default processor options. The current default Markdown dialect is `GitHub`.

`$PANDOC_EXE`
: Path to `pandoc` discovered from `PATH`, or an empty string when `pandoc` is
  not available.

`$PANDOC_CMD_MD2TEXT_CR`
: Code reference that builds the `pandoc` command used to render Markdown to
  plain text for README generation.

# FUNCTIONS

## bin_find

```perl
my $path = ASPEER::MakeMaker::Markdown::Pod::Constant::bin_find(qw(pandoc pandoc.exe));
```



( run in 0.631 second using v1.01-cache-2.11-cpan-5f8a54ce150 )