Jifty/Script.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Jifty/Action/AboutMe.pm ↑ Summary Jifty/Everything.pm »
1 package Jifty::Script;
2 1 ▶use App::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use base qw/App::CLI App::CLI::Command Jifty::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 0 ▶use Jifty::Everything;
Subroutine BEGIN: called CC=1 SCAR=2.6
6 Jifty::Everything->plugin_commands;
7 use Pod::Usage;
8  
9 =head1 NAME
10  
11 Jifty::Script - Base class for all bin/jifty commands
12  
13 =head1 METHODS
14  
15 =head2 prepare
16  
17 C<prepare> figures out which command to run. If the user wants
18 C<--help> give them help.
19  
20 In the normal case, let App::CLI figure out the command-line.
21 If they have no command on the command-line, but a JIFTY_COMMAND
22 environment variable, try that. Otherwise, if the GATEWAY_INTERFACE
23 environment variable is set, assume we are running under CGI with the
24 C<fastcgi> command. If all fails, shows the help.
25  
26 =cut
27  
28 sub prepare {
29 my $self = shift;
30 if ($ARGV[0] =~ /--?h(elp)?/i) {
31 $ARGV[0] = 'help';
32 }
33 elsif ( $ARGV[0] =~ /^(-v|--version|version)$/ ) {
34 print "This is Jifty, version $Jifty::VERSION\n";
35 exit 0;
36 }
37 elsif (!@ARGV) {
38 if ( my $cmd = $ENV{'JIFTY_COMMAND'} ) {
39 unshift @ARGV, $cmd;
40 }
41 elsif ( $ENV{GATEWAY_INTERFACE} ) {
42 unshift @ARGV, 'fastcgi';
43 }
44 else {
45 unshift @ARGV, 'help';
46 }
47 }
48 return $self->SUPER::prepare(@_);
49 }
50  
51 =head2 options
52  
53 =cut
54  
55 sub options {
56 return (
57 'h|help|?' => 'help',
58 'man' => 'man',
59 );
60 }
61  
62 =head2 alias
63  
64 The alias table lets users type C<fastcgi> in place of C<FastCGI>.
65  
66 =cut
67  
68 sub alias {
69 return (
70 fastcgi => "FastCGI",
71 writeccjs => "WriteCCJS",
72 )
73 }
74  
75 =head2 print_help
76  
77 Prints out help for the package using pod2usage.
78  
79 If the user specified --help, prints a brief usage message
80  
81 If the user specified --man, prints out a manpage
82  
83 =cut
84  
85 sub print_help {
86 my $self = shift;
87 my $msg = shift;
88  
89 $self->{'help'} = 1
90 if $msg && !( $self->{'help'} || $self->{'man'} );
91  
92 my %opts = (
93 -exitval => $msg? 1: 0,
94 -input => $self->filename,
95 -verbose => 99,
96 $msg? (-message => $msg): (),
97 );
98 # Option handling
99 pod2usage(
100 %opts,
101 -sections => 'NAME|SYNOPSIS',
102 ) if $self->{help};
103 pod2usage(
104 %opts,
105 -sections => '!METHODS',
106 ) if $self->{man};
107 }
108  
109 1;
« Jifty/Action/AboutMe.pm ↑ Summary Jifty/Everything.pm »