File Coverage

blib/lib/App/Git/Workflow/Command.pm
Criterion Covered Total %
statement 47 53 88.6
branch 9 14 64.2
condition 3 5 60.0
subroutine 10 10 100.0
pod 2 2 100.0
total 71 84 84.5


line stmt bran cond sub pod time code
1              
2             # Created on: 2014-03-11 20:58:59
3             # Create by: Ivan Wills
4             # $Id$
5             # $Revision$, $HeadURL$, $Date$
6             # $Revision$, $Source$, $Date$
7              
8             use strict;
9 21     21   1703 use warnings;
  21         43  
  21         590  
10 21     21   98 use version;
  21         41  
  21         518  
11 21     21   91 use Getopt::Long;
  21         36  
  21         118  
12 21     21   13242 use Data::Dumper qw/Dumper/;
  21         169342  
  21         93  
13 21     21   2873 use English qw/ -no_match_vars /;
  21         39  
  21         883  
14 21     21   116 use base qw/Exporter/;
  21         44  
  21         128  
15 21     21   5885  
  21         42  
  21         4734  
16             our $VERSION = version->new(1.1.19);
17             our @EXPORT_OK = qw/get_options/;
18             our %p2u_extra;
19              
20             my ($option, @options) = @_;
21             my ($caller_package) = caller;
22 104     104 1 6145 $caller_package .= '.pm';
23 104         371 $caller_package =~ s{::}{/}g;
24 104         301 $caller_package = $INC{$caller_package} || $0;
25 104         544  
26 104   66     486 Getopt::Long::Configure('bundling');
27             GetOptions(
28 104         559 $option,
29 104 100 50     3517 'verbose|v+',
30             'man',
31             'help',
32             'version!',
33             @options,
34             ) or pod2usage(
35             -verbose => 1,
36             -input => $caller_package,
37             %p2u_extra,
38             ) and return;
39              
40             if ( $option->{'version'} ) {
41             my $name = (caller)[0] . '::name';
42 100 100       80781 no strict qw/refs/; ## no critic
    100          
    100          
43 1         6 print "${$name} Version = $VERSION\n";
44 21     21   134 return;
  21         42  
  21         5431  
45 1         3 }
  1         104  
46 1         9 elsif ( $option->{'man'} ) {
47             pod2usage(
48             -verbose => 2,
49 1         8 -input => $caller_package,
50             %p2u_extra,
51             );
52             return;
53             }
54 1         34 elsif ( $option->{'help'} ) {
55             pod2usage(
56             -verbose => 1,
57 2         15 -input => $caller_package,
58             %p2u_extra,
59             );
60             return;
61             }
62 2         22  
63             return 1;
64             }
65 96         357  
66             my %opt = @_;
67             eval { require Pod::Usage };
68             if ($@) {
69 7     7 1 3501 my $found = 0;
70 7         20 open my $fh, '<', $opt{-input};
  7         2974  
71 7 50       237311 while ( $_ = <$fh> ) {
72 0         0 if (/^__DATA__$/) {
73 0         0 $found = 1;
74 0         0 }
75 0 0       0 elsif ($found) {
    0          
76 0         0 print $_;
77             }
78             }
79 0         0 }
80             else {
81             Pod::Usage::pod2usage(@_);
82             }
83              
84 7         48 return 1;
85             }
86              
87 7         206492 1;
88              
89              
90             =head1 NAME
91              
92             App::Git::Workflow::Command - Helper for other commands
93              
94             =head1 VERSION
95              
96             This documentation refers to App::Git::Workflow::Command version 1.1.19
97              
98             =head1 SYNOPSIS
99              
100             use App::Git::Workflow::Command qw/get_option/;
101              
102             my %option;
103             get_options( \%option, 'test|t!', 'quiet|q' );
104              
105             =head1 DESCRIPTION
106              
107             Does the boilerplate for other command modules.
108              
109             =head1 SUBROUTINES/METHODS
110              
111             =head2 C<get_options ($option_hash, @options)>
112              
113             Just a wrapper for L<Getopt::Long>'s C<GetOptions> which configures bundling
114             and adds verbose, help, man and version options. Also if C<GetOptions> fails
115             usage info will be displayed.
116              
117             =head2 C<pod2usage ()>
118              
119             Wrapper for L<Pod::Usage>'s C<pod2usage> to work around Windows' Git Bash tool
120             missing the library.
121              
122             =head1 DIAGNOSTICS
123              
124             =head1 CONFIGURATION AND ENVIRONMENT
125              
126             =head1 DEPENDENCIES
127              
128             =head1 INCOMPATIBILITIES
129              
130             =head1 BUGS AND LIMITATIONS
131              
132             There are no known bugs in this module.
133              
134             Please report problems to Ivan Wills (ivan.wills@gmail.com).
135              
136             Patches are welcome.
137              
138             =head1 AUTHOR
139              
140             Ivan Wills - (ivan.wills@gmail.com)
141              
142             =head1 LICENSE AND COPYRIGHT
143              
144             Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
145             All rights reserved.
146              
147             This module is free software; you can redistribute it and/or modify it under
148             the same terms as Perl itself. See L<perlartistic>. This program is
149             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
150             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
151             PARTICULAR PURPOSE.
152              
153             =cut