| 1 | package String::ShortenHostname::App; | ||
| 2 | # ABSTRACT: class for wrapping getopt options to the class interface | ||
| 3 | |||
| 4 | use Moose; | ||
| 5 | use IO::Handle; | ||
| 6 | |||
| 7 | our $VERSION = '0.006'; # VERSION | ||
| 8 | |||
| 9 | |||
| 10 | extends 'String::ShortenHostname'; | ||
| 11 | with 'MooseX::Getopt'; | ||
| 12 | |||
| 13 | has '+length' => ( | ||
| 14 | traits => ['Getopt'], | ||
| 15 | cmd_aliases => "l", | ||
| 16 | documentation => "the desired length of the hostname string", | ||
| 17 | ); | ||
| 18 | |||
| 19 | has '+keep_digits_per_domain' => ( | ||
| 20 | traits => ['Getopt'], | ||
| 21 | cmd_aliases => "d", | ||
| 22 | documentation => "number of digits per domain", | ||
| 23 | ); | ||
| 24 | |||
| 25 | has '+domain_edge' => ( | ||
| 26 | isa => 'Str', | ||
| 27 | traits => ['Getopt'], | ||
| 28 | cmd_aliases => "e", | ||
| 29 | documentation => "edge string for truncation of domain", | ||
| 30 | ); | ||
| 31 | |||
| 32 | has '+cut_middle' => ( | ||
| 33 | traits => ['Getopt'], | ||
| 34 | cmd_aliases => "m", | ||
| 35 | documentation => "dont truncate, cut in the middle of domain", | ||
| 36 | ); | ||
| 37 | |||
| 38 | has '+force' => ( | ||
| 39 | traits => ['Getopt'], | ||
| 40 | cmd_aliases => "f", | ||
| 41 | documentation => "force string length (truncate)", | ||
| 42 | ); | ||
| 43 | |||
| 44 | has '+force_edge' => ( | ||
| 45 | isa => 'Str', | ||
| 46 | traits => ['Getopt'], | ||
| 47 | cmd_aliases => "E", | ||
| 48 | documentation => "edge string for forced truncation of string", | ||
| 49 | ); | ||
| 50 | |||
| 51 | sub run { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | if( @{$self->extra_argv} ) { | ||
| 55 | foreach my $hostname ( @{$self->extra_argv} ) { | ||
| 56 | print $self->shorten($hostname)."\n"; | ||
| 57 | } | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | |||
| 61 | my $stdin = IO::Handle->new_from_fd(fileno(STDIN),"r") | ||
| 62 | or die('cant open STDIN: '.$@); | ||
| 63 | while( my $line = $stdin->getline ) { | ||
| 64 | chomp($line); | ||
| 65 | print $self->shorten($line)."\n"; | ||
| 66 | } | ||
| 67 | $stdin->close; | ||
| 68 | |||
| 69 | return; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | |||
| 75 | __END__ |