File Coverage

blib/lib/Getopt/Long/Negate/EN.pm
Criterion Covered Total %
statement 35 35 100.0
branch 42 42 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 83 83 100.0


line stmt bran cond sub pod time code
1             package Getopt::Long::Negate::EN;
2              
3             our $DATE = '2016-03-01'; # DATE
4             our $VERSION = '0.05'; # VERSION
5              
6 1     1   474 use 5.010001;
  1         2  
7 1     1   3 use strict;
  1         1  
  1         13  
8 1     1   3 use warnings;
  1         1  
  1         18  
9              
10 1     1   3 use Exporter qw(import);
  1         1  
  1         493  
11             our @EXPORT_OK = qw(negations_for_option);
12              
13             sub negations_for_option {
14 23     23 1 38 my $word = shift;
15              
16 23 100       204 if ($word =~ /\Awith([_-].+)/ ) { return ("without$1") }
  1 100       7  
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
17 1         5 elsif ($word =~ /\Awithout([_-].+)/) { return ("with$1") }
18              
19 1         6 elsif ($word =~ /\Ais([_-].+)/ ) { return ("isnt$1") }
20 1         5 elsif ($word =~ /\Aisnt([_-].+)/ ) { return ("is$1") }
21 1         5 elsif ($word =~ /\Aare([_-].+)/ ) { return ("arent$1") }
22 1         5 elsif ($word =~ /\Aarent([_-].+)/ ) { return ("are$1") }
23              
24 1         6 elsif ($word =~ /\Ahas([_-].+)/ ) { return ("hasnt$1") }
25 1         6 elsif ($word =~ /\Ahave([_-].+)/ ) { return ("havent$1") }
26 1         5 elsif ($word =~ /\Ahasnt([_-].+)/ ) { return ("has$1") }
27 1         6 elsif ($word =~ /\Ahavent([_-].+)/ ) { return ("have$1") }
28              
29 1         6 elsif ($word =~ /\Acan([_-].+)/ ) { return ("cant$1") }
30 1         6 elsif ($word =~ /\Acant([_-].+)/ ) { return ("can$1") }
31              
32 1         5 elsif ($word =~ /\Aenabled([_-].+)/ ) { return ("disabled$1") }
33 1         6 elsif ($word =~ /\Adisabled([_-].+)/) { return ("enabled$1") }
34 1         6 elsif ($word =~ /\Aenable([_-].+)/ ) { return ("disable$1") }
35 1         6 elsif ($word =~ /\Adisable([_-].+)/) { return ("enable$1") }
36              
37 1         5 elsif ($word =~ /\Aallowed([_-].+)/ ) { return ("disallowed$1") }
38 1         6 elsif ($word =~ /\Adisallowed([_-].+)/) { return ("allowed$1") }
39 1         20 elsif ($word =~ /\Aallow([_-].+)/ ) { return ("disallow$1") }
40 1         7 elsif ($word =~ /\Adisallow([_-].+)/) { return ("allow$1") }
41              
42 2         9 elsif ($word =~ /\Ano[_-](.+)/ ) { return ($1) }
43              
44             else {
45             # default from Getopt::Long
46 1         9 return ("no-$word", "no$word");
47             }
48             }
49              
50             1;
51             # ABSTRACT: Better negation of boolean option names
52              
53             __END__
54              
55             =pod
56              
57             =encoding UTF-8
58              
59             =head1 NAME
60              
61             Getopt::Long::Negate::EN - Better negation of boolean option names
62              
63             =head1 VERSION
64              
65             This document describes version 0.05 of Getopt::Long::Negate::EN (from Perl distribution Getopt-Long-Negate-EN), released on 2016-03-01.
66              
67             =head1 SYNOPSIS
68              
69             use Getopt::Long::Negate::EN qw(negations_for_option);
70              
71             # the Getopt::Long's default
72             @negs = negations_for_option('foo'); # ('no-foo', 'nofoo')
73              
74             @negs = negations_for_option('with-foo'); # ('without-foo')
75             @negs = negations_for_option('without-foo'); # ('with-foo')
76              
77             @negs = negations_for_option('is-foo'); # ('isnt-foo')
78             @negs = negations_for_option('isnt-foo'); # ('is-foo')
79             @negs = negations_for_option('are-foo'); # ('isnt-foo')
80             @negs = negations_for_option('arent-foo'); # ('arent-foo')
81              
82             @negs = negations_for_option('has-foo'); # ('hasnt-foo')
83             @negs = negations_for_option('hasnt-foo'); # ('has-foo')
84             @negs = negations_for_option('have-foo'); # ('havent-foo')
85             @negs = negations_for_option('havent-foo'); # ('have-foo')
86              
87             @negs = negations_for_option('can-foo'); # ('cant-foo')
88             @negs = negations_for_option('cant-foo'); # ('can-foo')
89              
90             @negs = negations_for_option('enabled-foo'); # ('disabled-foo')
91             @negs = negations_for_option('disabled-foo');# ('enabled-foo')
92             @negs = negations_for_option('enable-foo'); # ('disable-foo')
93             @negs = negations_for_option('disable-foo'); # ('enable-foo')
94              
95             @negs = negations_for_option('allowed-foo'); # ('disallowed-foo')
96             @negs = negations_for_option('disallowed-foo'); # ('allowed-foo')
97             @negs = negations_for_option('allow-foo'); # ('disallow-foo')
98             @negs = negations_for_option('disallow-foo'); # ('allow-foo')
99              
100             @negs = negations_for_option('no-foo'); # ('foo')
101              
102             =head1 DESCRIPTION
103              
104             This module aims to provide a nicer negative boolean option names. By default,
105             L<Getopt::Long> provides options C<--foo> as well as C<--no-foo> and C<--nofoo>
106             if you specify boolean option specification C<foo!>. But this produces
107             awkward/incorrect English word like C<--nowith-foo> or C<--no-is-foo>. In those
108             two cases, C<--without-foo> and C<--isnt-foo> are better option names.
109              
110             =head1 FUNCTIONS
111              
112             None are exported by default, but they are exportable.
113              
114             =head2 negations_for_option($str) => list
115              
116             =head1 HOMEPAGE
117              
118             Please visit the project's homepage at L<https://metacpan.org/release/Getopt-Long-Negate-EN>.
119              
120             =head1 SOURCE
121              
122             Source repository is at L<https://github.com/perlancar/perl-Getopt-Long-Negate-EN>.
123              
124             =head1 BUGS
125              
126             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Long-Negate-EN>
127              
128             When submitting a bug or request, please include a test-file or a
129             patch to an existing test-file that illustrates the bug or desired
130             feature.
131              
132             =head1 AUTHOR
133              
134             perlancar <perlancar@cpan.org>
135              
136             =head1 COPYRIGHT AND LICENSE
137              
138             This software is copyright (c) 2016 by perlancar@cpan.org.
139              
140             This is free software; you can redistribute it and/or modify it under
141             the same terms as the Perl 5 programming language system itself.
142              
143             =cut