| 1 | package MYDan::Util::MIO; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | MYDan::Util::MIO - Interface for MYDan::Util::MIO modules | ||
| 6 | |||
| 7 | =cut | ||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | use Carp; | ||
| 12 | use File::Spec; | ||
| 13 | |||
| 14 | our %RUN = ( max => 128, timeout => 300, log => \*STDERR ); | ||
| 15 | our %MAX = ( buffer => 1024 * 16, period => 0.01 ); | ||
| 16 | |||
| 17 | sub net | ||
| 18 | { | ||
| 19 | my ( $class, %self ) = shift; | ||
| 20 | |||
| 21 | for my $node ( @_ ) | ||
| 22 | { | ||
| 23 | confess "duplicate addr: $node" if $self{$node}; | ||
| 24 | $self{$node} = $node =~ /^[^:]+:\d+$/o | ||
| 25 | ? 1 : File::Spec->file_name_is_absolute( $node ) | ||
| 26 | ? 0 : confess "$node: invalid unix domain socket"; | ||
| 27 | } | ||
| 28 | |||
| 29 | bless \%self, ref $class || $class; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub cmd | ||
| 33 | { | ||
| 34 | my ( $class, %self, %cmd ) = splice @_; | ||
| 35 | |||
| 36 | while ( my ( $node, $cmd ) = each %self ) | ||
| 37 | { | ||
| 38 | confess "command undefined for $node" unless $cmd; | ||
| 39 | $self{$node} = $cmd{$cmd} ||= ref $cmd ? $cmd : [ $cmd ]; | ||
| 40 | } | ||
| 41 | |||
| 42 | bless \%self, ref $class || $class; | ||
| 43 | } | ||
| 44 | |||
| 45 | 1; |