| 1 | #============================================================================= | ||
| 2 | # | ||
| 3 | # Module: Term::CLI::Base | ||
| 4 | # | ||
| 5 | # Description: Generic role for Term::CLI classes | ||
| 6 | # | ||
| 7 | # Author: Steven Bakker (SBAKKER), <sbakker@cpan.org> | ||
| 8 | # Created: 10/02/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::Base 0.051003 { | ||
| 24 | |||
| 25 | use Modern::Perl 1.20140107; | ||
| 26 | use Term::CLI::ReadLine; | ||
| 27 | |||
| 28 | use Types::Standard 1.000005 qw( | ||
| 29 | Str | ||
| 30 | ); | ||
| 31 | |||
| 32 | use Moo 1.000001; | ||
| 33 | use namespace::clean 0.25; | ||
| 34 | |||
| 35 | has name => ( is => 'ro', isa => Str, required => 1 ); | ||
| 36 | has error => ( is => 'rwp', isa => Str, default => sub {''} ); | ||
| 37 | |||
| 38 | sub term { return Term::CLI::ReadLine->term } | ||
| 39 | |||
| 40 | sub set_error { | ||
| 41 | my ($self, @value) = @_; | ||
| 42 | if (!@value or !defined $value[0]) { | ||
| 43 | $self->_set_error(''); | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | $self->_set_error(join('', @value)); | ||
| 47 | } | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | |||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ |