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