| 1 | #============================================================================= | ||
| 2 | # | ||
| 3 | # Module: Term::CLI::Argument::Number::Int | ||
| 4 | # | ||
| 5 | # Description: Class for integer arguments in Term::CLI | ||
| 6 | # | ||
| 7 | # Author: Steven Bakker (SBAKKER), <sbakker@cpan.org> | ||
| 8 | # Created: 22/01/18 | ||
| 9 | # | ||
| 10 | # Copyright (c) 2018 Steven Bakker | ||
| 11 | # | ||
| 12 | # This module is free software; you can redistribute it and/or modify | ||
| 13 | # it under the same terms as Perl itself. See "perldoc perlartistic." | ||
| 14 | # | ||
| 15 | # This software is distributed in the hope that it will be useful, | ||
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 18 | # | ||
| 19 | #============================================================================= | ||
| 20 | |||
| 21 | use 5.014_001; | ||
| 22 | |||
| 23 | package Term::CLI::Argument::Number::Int 0.051003 { | ||
| 24 | |||
| 25 | use Modern::Perl 1.20140107; | ||
| 26 | use Moo 1.000001; | ||
| 27 | use namespace::clean 0.25; | ||
| 28 | |||
| 29 | extends 'Term::CLI::Argument::Number'; | ||
| 30 | |||
| 31 | sub coerce_value { | ||
| 32 | my $val = $_[1]; | ||
| 33 | |||
| 34 | if ($val =~ /^[+-]?\d+$/) { | ||
| 35 | return int($val); | ||
| 36 | } | ||
| 37 | return undef; | ||
| 38 | } | ||
| 39 | |||
| 40 | } | ||
| 41 | |||
| 42 | 1; | ||
| 43 | |||
| 44 | __END__ |