-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arthur Axel 'fREW' Schmidt
committed
Jun 2, 2014
0 parents
commit 5d47828
Showing
7 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Pod-Weaver-Plugin-Exec-* | ||
.build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Revision history for {{$dist->name}} | ||
|
||
{{$NEXT}} | ||
- initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?? |