ASPEER-MakeMaker-Markdown-Publish
view release on metacpan or search on metacpan
t/01-targets.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use lib 'lib';
use Config;
use Cwd qw(abs_path getcwd);
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use JSON::PP qw(decode_json);
use MIME::Base64 qw(decode_base64);
use Test::More;
use ASPEER::MakeMaker::Markdown::Publish::MM;
sub blurp {
my ($fn, $text)=@_;
open(my $output_fh, '>', $fn) || die "unable to write $fn: $!";
print {$output_fh} $text;
close($output_fh) || die "unable to close $fn: $!";
return 1;
}
sub slurp {
my ($fn)=@_;
open(my $input_fh, '<', $fn) || die "unable to read $fn: $!";
local $/=undef;
my $text=<$input_fh>;
close($input_fh) || die "unable to close $fn: $!";
return $text;
}
# Locate the adapter and shared parent before entering a disposable project
#
my $cwd=getcwd();
my $adapter_lib_dn=abs_path('lib');
my $common_pm_fn=abs_path($INC{'ASPEER/MakeMaker/MM.pm'});
$common_pm_fn=~s{[/\\]ASPEER[/\\]MakeMaker[/\\]MM\.pm$}{};
my $temporary_dn=tempdir(CLEANUP => 1);
chdir($temporary_dn) || die "unable to chdir $temporary_dn: $!";
make_path('lib/Sample', 'doc', 'local lib/Markdown');
my $local_lib_dn=abs_path('local lib');
# The runtime publisher stub records exactly what the generated target passes
#
blurp('local lib/Markdown/Publish.pm', <<'PUBLISH_STUB');
package Markdown::Publish;
use JSON::PP qw(encode_json);
sub new {my ($class, $config_hr)=@_; return bless({config => $config_hr}, $class)}
sub run {
my ($self, $action)=@_;
open(my $output_fh, '>>', 'target.log') || die "unable to write target log: $!";
print {$output_fh} encode_json({config => $self->{'config'}, action => $action}), "\n";
close($output_fh) || die "unable to close target log: $!";
return 1;
}
1;
PUBLISH_STUB
blurp('lib/Sample.pm', "package Sample;\nour \$VERSION='0.001';\n1;\n");
blurp('lib/Sample.pm.md', "# NAME\n\nSample - generated documentation target fixture\n");
blurp('README.md', "# Sample\n\nGenerated documentation target fixture.\n");
blurp('MANIFEST', "lib/Sample.pm\nlib/Sample.pm.md\nREADME.md\ndoc/guide.md\n");
blurp('doc/guide.md', "# Guide\n\nText.\n");
blurp('Makefile.PL', <<'MAKEFILE_PL');
( run in 1.969 second using v1.01-cache-2.11-cpan-234fa220139 )