| 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
| |||||||||||
| 22 | ) or usage(); | ||||||||||
| 23 | 2 | ▶ | if ($help) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | system("perldoc $0"); | |||||||||
| 25 | 0 | exit; | |||||||||
| 26 | } | ||||||||||
| 27 | 2 | ▶ | %params = map { defined( $params{$_} ) ? ( $_, $params{$_} ) : () } keys(%params); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 2 | ▶ | if ( $params{plugins} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $params{plugins} = [ split( /\s*,\s*/, $params{plugins} ) ]; | |||||||||
| 30 | } | ||||||||||
| 31 | 2 | ▶ | my %run_args = defined($args) ? %{ json_decode($args) } : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 2 | my $tempdir = tempdir( 'mason-XXXX', TMPDIR => 1, CLEANUP => 1 ); | |||||||||
| 34 | 2 | my $file; | |||||||||
| 35 | 2 | ▶ | if ($source) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 43 | 1 | ▶ | if ( !$file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | $file = "$tempdir/stdin.mc"; | |||||||||
| 45 | 0 | open( my $fh, ">", $file ); | |||||||||
| 46 | 0 | ▶ | while (<STDIN>) { print $fh $_ } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||