File Coverage

blib/lib/Net/SSH/Perl/Util.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 6 66.6
condition n/a
subroutine 5 5 100.0
pod n/a
total 37 39 94.8


line stmt bran cond sub pod time code
1             package Net::SSH::Perl::Util;
2 5     5   32 use strict;
  5         12  
  5         176  
3 5     5   19 use warnings;
  5         9  
  5         227  
4              
5 5     5   23 use vars qw( %FUNC_TO_MOD %EXPORT_TAGS );
  5         6  
  5         1363  
6              
7             %FUNC_TO_MOD = (
8             _crc32 => 'SSH1Misc',
9             _compute_session_id => 'SSH1MP',
10             _mp_linearize => 'SSH1MP',
11             _check_host_in_hostfile => 'Hosts',
12             _all_keys_for_host => 'Hosts',
13             _add_host_to_hostfile => 'Hosts',
14             _remove_host_from_hostfile=> 'Hosts',
15             _load_private_key => 'Authfile',
16             _load_public_key => 'Authfile',
17             _save_private_key => 'Authfile',
18             _respond_to_rsa_challenge => 'RSA',
19             _rsa_public_encrypt => 'RSA',
20             _rsa_private_decrypt => 'RSA',
21             _prompt => 'Term',
22             _read_passphrase => 'Term',
23             _read_yes_or_no => 'Term',
24             _current_user_win32 => 'Win32',
25             _socketpair => 'Win32',
26             );
27              
28             %EXPORT_TAGS = (
29             hosts => [ qw( _check_host_in_hostfile _all_keys_for_host
30             _add_host_to_hostfile _remove_host_from_hostfile ) ],
31             rsa => [ qw( _rsa_public_encrypt _rsa_private_decrypt
32             _respond_to_rsa_challenge ) ],
33             ssh1mp => [ qw( _compute_session_id _mp_linearize ) ],
34             authfile => [ qw( _load_public_key _load_private_key _save_private_key ) ],
35             win32 => [ qw( _current_user_win32 _socketpair ) ],
36             all => [ keys %FUNC_TO_MOD ],
37             );
38              
39             sub import {
40 9     9   19 my $class = shift;
41 9         20 my $callpack = caller;
42              
43 9         15 my @to_export;
44 9         25 my @args = @_;
45 9         24 for my $item (@args) {
46             push @to_export,
47 22 50       77 $item =~ s/^:// ? @{ $EXPORT_TAGS{$item} || [] } : $item;
  9 100       43  
48             }
49              
50 9         16 my %loaded;
51 5     5   31 no strict 'refs'; ## no critic
  5         9  
  5         1100  
52 9         16 for my $func (@to_export) {
53 44         130 my $mod = join '::', __PACKAGE__, $FUNC_TO_MOD{$func};
54 44 50       152 unless ($loaded{$mod}) {
55 44         173 (my $lib = $mod . ".pm") =~ s!::!/!g;
56 44         9764 require $lib;
57             }
58 44         98 *{"${callpack}::$func"} = \&{"${mod}::$func"};
  44         468  
  44         185  
59             }
60             }
61              
62             1;
63             __END__