File Coverage

blib/lib/Code/TidyAll/Role/GenericExecutable.pm
Criterion Covered Total %
statement 30 30 100.0
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 40 41 97.5


line stmt bran cond sub pod time code
1             package Code::TidyAll::Role::GenericExecutable;
2              
3 2     2   1043 use strict;
  2         4  
  2         57  
4 2     2   11 use warnings;
  2         4  
  2         58  
5              
6 2     2   11 use IPC::Run3 qw(run3);
  2         4  
  2         115  
7 2     2   14 use Specio::Library::Builtins;
  2         5  
  2         29  
8 2     2   19449 use Specio::Library::String;
  2         6  
  2         16  
9 2     2   5380 use Text::ParseWords qw(shellwords);
  2         2730  
  2         122  
10 2     2   14 use Try::Tiny;
  2         5  
  2         101  
11              
12 2     2   12 use Moo::Role;
  2         4  
  2         16  
13              
14             with 'Code::TidyAll::Role::RunsCommand';
15              
16             our $VERSION = '0.83';
17              
18             has 'cmd' => (
19             is => 'ro',
20             required => 1,
21             );
22              
23             has file_flag => (
24             is => 'ro',
25             isa => t('NonEmptyStr'),
26             predicate => '_has_file_flag',
27             );
28              
29             sub _run_generic_executable_or_die {
30 9     9   21 my $self = shift;
31 9         19 my $file = shift;
32              
33 9         36 my @argv;
34 9 50       63 push @argv, $self->file_flag if $self->_has_file_flag;
35 9         42 push @argv, $file;
36              
37 9         51 return $self->_run_or_die(@argv);
38             }
39              
40             1;
41              
42             # ABSTRACT: A role for plugins which allow you to use any executable as a transformer or validator
43              
44             __END__
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             Code::TidyAll::Role::GenericExecutable - A role for plugins which allow you to use any executable as a transformer or validator
53              
54             =head1 VERSION
55              
56             version 0.83
57              
58             =head1 SYNOPSIS
59              
60             package Whatever;
61             use Moo;
62             with 'Code::TidyAll::Role::GenericExecutable';
63              
64             =head1 DESCRIPTION
65              
66             This role exists for the benefit of the
67             L<Code::TidyAll::Plugin::GenericTransformer> and
68             L<Code::TidyAll::Plugin::GenericValidator> plugin classes.
69              
70             =head1 ATTRIBUTES
71              
72             =over
73              
74             =item cmd
75              
76             This attribute is require for any class which consumes this role.
77              
78             =item file_flag
79              
80             If this is set then this flag is used to indicate the file passed to the
81             command, for example something like C<-f>, C<--file>, or C<--input>. By
82             default, the file is simply passed as the last argument to the command.
83              
84             =back
85              
86             =head1 SUPPORT
87              
88             Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>.
89              
90             =head1 SOURCE
91              
92             The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>.
93              
94             =head1 AUTHORS
95              
96             =over 4
97              
98             =item *
99              
100             Jonathan Swartz <swartz@pobox.com>
101              
102             =item *
103              
104             Dave Rolsky <autarch@urth.org>
105              
106             =back
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             The full text of the license can be found in the
116             F<LICENSE> file included with this distribution.
117              
118             =cut