| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use Object::Pad ':experimental(:all)'; | ||
| 4 | |||
| 5 | package nosh; | ||
| 6 | |||
| 7 | class nosh; | ||
| 8 | |||
| 9 | use utf8; | ||
| 10 | use v5.40; | ||
| 11 | |||
| 12 | use lib 'lib'; | ||
| 13 | |||
| 14 | use Getopt::Long | ||
| 15 | qw(GetOptionsFromArray :config no_ignore_case auto_abbrev passthrough long_prefix_pattern=--?); | ||
| 16 | |||
| 17 | use List::Util 'all'; | ||
| 18 | use IPC::Nosh; | ||
| 19 | use IPC::Nosh::Common; | ||
| 20 | |||
| 21 | field $argv : param; | ||
| 22 | field $debug : mutator; | ||
| 23 | |||
| 24 | # field $stdin; | ||
| 25 | field $autoflush : mutator //= 1; | ||
| 26 | field $autochomp : mutator //= 1; | ||
| 27 | field $verbose : mutator = 1; | ||
| 28 | field @barearg; | ||
| 29 | field $cmd : mutator = []; | ||
| 30 | |||
| 31 | ADJUST { #{ # :params (:$autochomp, :$autoflush) { | ||
| 32 | my %clidest = ( cmd => $cmd ); | ||
| 33 | |||
| 34 | GetOptionsFromArray( | ||
| 35 | $argv, \%clidest, 'cmd:s@', | ||
| 36 | 'verbose+', | ||
| 37 | 'version', | ||
| 38 | 'help|?', 'debug+', #'stdin' | ||
| 39 | 'autoflush!', | ||
| 40 | 'autochomp!', | ||
| 41 | '<>' => sub ($barearg) { | ||
| 42 | push @$cmd, $barearg #map { split /\s+/, $_ } $barearg; | ||
| 43 | } | ||
| 44 | ); | ||
| 45 | |||
| 46 | foreach my ( $k, $v ) (%clidest) { | ||
| 47 | $self->$k = $v if defined $v; | ||
| 48 | } | ||
| 49 | |||
| 50 | dmsg $self, \%clidest | ||
| 51 | |||
| 52 | } | ||
| 53 | |||
| 54 | method nosh ( $asdf = undef, %fdsa ) { | ||
| 55 | |||
| 56 | my $run = run( | ||
| 57 | $cmd, | ||
| 58 | |||
| 59 | out => sub ( $line, @ ) { | ||
| 60 | |||
| 61 | # dmsg \@opt; | ||
| 62 | say $line; | ||
| 63 | }, | ||
| 64 | autoflush => $autoflush, | ||
| 65 | autochomp => $autochomp, | ||
| 66 | ); | ||
| 67 | dmsg $run; | ||
| 68 | } | ||
| 69 | |||
| 70 | method cli : common ($argv = \@ARGV) { | ||
| 71 | my $self = $class->new( argv => $argv ); | ||
| 72 | $self->nosh; | ||
| 73 | } | ||
| 74 | |||
| 75 | package main; | ||
| 76 | |||
| 77 | use utf8; | ||
| 78 | use v5.40; | ||
| 79 | |||
| 80 | nosh->cli( \@ARGV ); | ||
| 81 | |||
| 82 | use lib 'lib'; | ||
| 83 | use IPC::Nosh::Mux; | ||
| 84 | use IPC::Nosh::Common; | ||
| 85 | |||
| 86 | # my @arr; | ||
| 87 | |||
| 88 | # tie @arr, 'IPC::Nosh::Mux', | ||
| 89 | # autochomp => 1, | ||
| 90 | # on => { | ||
| 91 | # line => sub ($line) { | ||
| 92 | # warn $line; | ||
| 93 | # } | ||
| 94 | # }; | ||
| 95 | |||
| 96 | # dmsg \@arr, tied @arr; | ||
| 97 | # fn => './fsadfsdfsdf'; |