File Coverage

lib/IOMux/Open.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 8 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 32 36 88.8


line stmt bran cond sub pod time code
1             # Copyrights 2011-2020 by [Mark Overmeer ].
2             # For other contributors see ChangeLog.
3             # See the manual pages for details on the licensing terms.
4             # Pod stripped from pm file by OODoc 2.02.
5             # This code is part of distribution IOMux. Meta-POD processed with OODoc
6             # into POD and HTML manual-pages. See README.md
7             # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8              
9             package IOMux::Open;
10 2     2   1735 use vars '$VERSION';
  2         4  
  2         89  
11             $VERSION = '1.01';
12              
13              
14 2     2   10 use warnings;
  2         3  
  2         42  
15 2     2   7 use strict;
  2         4  
  2         36  
16              
17 2     2   8 use Log::Report 'iomux';
  2         3  
  2         9  
18              
19             my %modes =
20             ( '-|' => 'IOMux::Pipe::Read'
21             , '|-' => 'IOMux::Pipe::Write'
22             , '|-|' => 'IOMux::IPC'
23             , '|=|' => 'IOMux::IPC'
24             , '>' => 'IOMux::File::Write'
25             , '>>' => 'IOMux::File::Write'
26             , '<' => 'IOMux::File::Read'
27             , tcp => 'IOMux::Net::TCP'
28             );
29              
30             sub import(@)
31 3     3   343 { my $class = shift;
32 3         18 foreach my $mode (@_)
33 2 50       9 { my $impl = $modes{$mode}
34             or error __x"unknown mode {mode} in use {pkg}"
35             , mode => $mode, pkg => $class;
36 2         94 eval "require $impl";
37 2 50       15 panic $@ if $@;
38             }
39             }
40            
41              
42             sub new($@)
43 4     4 1 8 { my ($class, $mode) = (shift, shift);
44 4 50       10 my $real = $modes{$mode}
45             or error __x"unknown mode '{mode}' to open() on mux", mode => $mode;
46              
47 4 50       48 $real->can('open')
48             or error __x"package {pkg} for mode '{mode}' not required by {me}"
49             , pkg => $real, mode => $mode, me => $class;
50              
51 4         15 $real->open($mode, @_);
52             }
53              
54             #--------------
55              
56             1;