blib/lib/Mason/App.pm

filter: Statementstmt 85.2% 52 / 61 Branchbran 61.1% 11 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 3 totaltotal 78.4% 73 / 93 CC 10 SCAR 19.3
CC
10
Cov
80%
run
12.6
usage
2.0
BEGIN
1.0
CRAP 6.9
↑ Summary blib/lib/Mason/Test/Class.pm »
1 package Mason::App;
2 2 $Mason::App::VERSION = '2.24';
3 2 ▶use Cwd qw(realpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Mason;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Mason::Util qw(json_decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 my $usage =
13 "usage: $0 [--data-dir dir] [--plugins Plugin1,Plugin2] [--args json-string] [-e source] [template-file]";
14  
15 2 ▶sub run {
Subroutine run: called CC=10 SCAR=25.4
Pod undocumented
16 2 my ( %params, $args, $source, $help );
17 GetOptions(
18 'args=s' => \$args,
19 'e=s' => \$source,
20 'h|help' => \$help,
21 2 ▶ map { dashify($_) . "=s" => \$params{$_} } qw(data_dir plugins)
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("args=s", \$args, "e=s", \$source, "h|help", \$help, map({dashify($_) . '=s', \$params{$_};} "data_dir", "plugins")) or usage() 2 0 2
22 ) or usage();
23 2 ▶ if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 0 2 2
24 0 system("perldoc $0");
25 0 exit;
26 }
27 2 ▶ %params = map { defined( $params{$_} ) ? ( $_, $params{$_} ) : () } keys(%params);
Branch: 1 branch
BranchTrueFalseTotal
defined $params{$_} ? : 1 3 4
28 2 ▶ if ( $params{plugins} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"plugins"}) 0 2 2
29 0 $params{plugins} = [ split( /\s*,\s*/, $params{plugins} ) ];
30 }
31 2 ▶ my %run_args = defined($args) ? %{ json_decode($args) } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 1 1 2
32  
33 2 my $tempdir = tempdir( 'mason-XXXX', TMPDIR => 1, CLEANUP => 1 );
34 2 my $file;
35 2 ▶ if ($source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source) { } 1 1 2
36 1 $file = "$tempdir/source.mc";
37 1 open( my $fh, ">", $file );
38 1 print $fh $source;
39 }
40 else {
41 1 $file = shift(@ARGV);
42 1 ▶ usage() if @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV 0 1 1
43 1 ▶ if ( !$file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 1 1
44 0 $file = "$tempdir/stdin.mc";
45 0 open( my $fh, ">", $file );
46 0 ▶ while (<STDIN>) { print $fh $_ }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline STDIN)) 0 0 0
47 }
48 }
49  
50 2 my $comp_root = dirname($file);
51 2 my $path = "/" . basename($file);
52 2 my $interp = Mason->new( comp_root => $comp_root, autoextend_request_path => 0, %params );
53 2 print $interp->run( $path, %run_args )->output . "\n";
54 }
55  
56 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
Pod undocumented
57 0 print "$usage\n";
58 0 exit;
59 }
60  
61 4 ▶sub dashify {
Subroutine dashify: called CC=1 SCAR=0.0
Pod undocumented
62 4 my $name = shift;
63 4 $name =~ s/_/-/g;
64 4 return $name;
65 }
66  
67 2 1;
68  
69 __END__
↑ Summary blib/lib/Mason/Test/Class.pm »