Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Jun 2, 2014
0 parents commit 5d47828
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pod-Weaver-Plugin-Exec-*
.build
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: perl
perl:
- 5.20
- 5.18
- 5.16
- 5.14
install:
- cpanm -nq --installdeps .
- cpanm -nq Devel::Cover::Report::Coveralls
script:
- PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path,subroutine prove -lrsv t
- cover
after_success:
- cover -report coveralls
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- initial release
14 changes: 14 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
requires 'perl' => 5.014000;

requires 'Moose';
requires 'Pod::Weaver::Role::Dialect';
requires 'Pod::Elemental::Transformer';
requires 'Capture::Tiny';
requires 'Moose::Autobox';
requires 'namespace::clean';

on test => sub {
requires 'Test::More' => 0.88;
requires 'Pod::Elemental';
requires 'Pod::Elemental::Transformer::Pod5';
};
18 changes: 18 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name = Pod-Weaver-Plugin-Exec
author = Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
license = Perl_5
copyright_holder = Arthur Axel "fREW" Schmidt
version = 0.001000

[NextRelease]
[@Git]
[@Basic]
[GithubMeta]
issues = 1

[MetaJSON]
[PodWeaver]
[PkgVersion]
[ReadmeFromPod]
[PodSyntaxTests]
[Prereqs::FromCPANfile]
76 changes: 76 additions & 0 deletions lib/Pod/Weaver/Plugin/Exec.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package Pod::Weaver::Plugin::Exec;

use Moose;
with 'Pod::Weaver::Role::Dialect';

sub translate_dialect {
Pod::Elemental::Transformer::Exec->new->transform_node($_[1])
}

package
Pod::Elemental::Transformer::Exec {

use Moose;
with 'Pod::Elemental::Transformer';

use Capture::Tiny 'capture_stdout';
use Moose::Autobox;
use namespace::clean;

sub transform_node {
my ($self, $node) = @_;
my $children = $node->children;

PASS: for (my $i = 0 ; $i < $children->length ; $i++) {
my $para = $children->[$i];
next
unless $para->isa('Pod::Elemental::Element::Pod5::Region')
and !$para->is_pod
and $para->format_name eq 'exec';

confess "exec transformer expects exec region to contain 1 Data para"
unless $para->children->length == 1
and $para->children->[0]->isa('Pod::Elemental::Element::Pod5::Data');

chomp(my $command = $para->children->[0]->content);
my $out = capture_stdout { system($command) };
$out = join "\n", map " $_", split /\n/, $out;

my $new_doc =
Pod::Elemental->read_string("\n\n=pod\n\n$out\n\n");
Pod::Elemental::Transformer::Pod5->transform_node($new_doc);
$new_doc->children->shift
while $new_doc->children->[0]
->isa('Pod::Elemental::Element::Pod5::Nonpod');

splice @$children, $i, 1, $new_doc->children->flatten;
}

return $node;
}
}

1;

__END__
=pod
=head1 SYNOPSIS
In your F<weaver.ini>:
[@Default]
[-Exec]
In the pod of one of your modules:
=head1 EXAMPLE OUTPUT
=for exec
perl maint/script.pl
=head1 DESCRIPTION
This is a L<Pod::Weaver> plugin that will take the output of a command and
insert it as literal data into the pod.
44 changes: 44 additions & 0 deletions t/simple.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use strict;
use warnings;

use Test::More;

use Pod::Elemental;
use Pod::Elemental::Transformer::Pod5;
use Pod::Weaver::Plugin::Exec;

my $str = do { local $/; <DATA> };

my $doc = Pod::Elemental->read_string($str);

Pod::Elemental::Transformer::Pod5->new->transform_node($doc);
Pod::Elemental::Transformer::Exec->new->transform_node($doc);

is($doc->as_pod_string, <<'POD');
=pod
=head1 Welcome to Pod!
1
2
Right??
=cut
POD

done_testing;

__DATA__
=pod
=head1 Welcome to Pod!
=for exec
perl -E'say 1'
=for exec
perl -E'say 2'
Right??

0 comments on commit 5d47828

Please sign in to comment.