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-2015 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 2     2   2159 use warnings;
  2         5  
  2         61  
6 2     2   34 use strict;
  2         5  
  2         71  
7              
8             package IOMux::Open;
9 2     2   11 use vars '$VERSION';
  2         4  
  2         103  
10             $VERSION = '1.00';
11              
12              
13 2     2   11 use Log::Report 'iomux';
  2         4  
  2         23  
14              
15             my %modes =
16             ( '-|' => 'IOMux::Pipe::Read'
17             , '|-' => 'IOMux::Pipe::Write'
18             , '|-|' => 'IOMux::IPC'
19             , '|=|' => 'IOMux::IPC'
20             , '>' => 'IOMux::File::Write'
21             , '>>' => 'IOMux::File::Write'
22             , '<' => 'IOMux::File::Read'
23             , tcp => 'IOMux::Net::TCP'
24             );
25              
26             sub import(@)
27 3     3   461 { my $class = shift;
28 3         25 foreach my $mode (@_)
29 2 50       12 { my $impl = $modes{$mode}
30             or error __x"unknown mode {mode} in use {pkg}"
31             , mode => $mode, pkg => $class;
32 2         96 eval "require $impl";
33 2 50       33 panic $@ if $@;
34             }
35             }
36            
37              
38             sub new($@)
39 4     4 1 9 { my ($class, $mode) = (shift, shift);
40 4 50       13 my $real = $modes{$mode}
41             or error __x"unknown mode '{mode}' to open() on mux", mode => $mode;
42              
43 4 50       38 $real->can('open')
44             or error __x"package {pkg} for mode '{mode}' not required by {me}"
45             , pkg => $real, mode => $mode, me => $class;
46              
47 4         15 $real->open($mode, @_);
48             }
49              
50             #--------------
51              
52             1;