blib/lib/App/Netdisco/Util/PortMAC.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 48 CC 2 SCAR 12.8
CC
2
Cov
0%
get_port_macs
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 package App::Netdisco::Util::PortMAC;
2  
3 use Dancer qw/:syntax :script/;
4 use Dancer::Plugin::DBIC 'schema';
5  
6 use base 'Exporter';
7 our @EXPORT = ();
8 our @EXPORT_OK = qw/ get_port_macs /;
9 our %EXPORT_TAGS = (all => \@EXPORT_OK);
10  
11 =head1 NAME
12  
13 App::Netdisco::Util::PortMAC
14  
15 =head1 DESCRIPTION
16  
17 Helper subroutine to support parts of the Netdisco application.
18  
19 There are no default exports, however the C<:all> tag will export all
20 subroutines.
21  
22 =head1 EXPORT_OK
23  
24 =head2 get_port_macs
25  
26 Returns a Hash reference of C<< { MAC => IP } >> for all interface MAC
27 addresses supplied as array reference
28  
29 =cut
30  
31 sub get_port_macs {
32 my ($fw_mac_list) = $_[0];
33 my $port_macs = {};
34 return {} unless ref [] eq ref $fw_mac_list and @{$fw_mac_list} >= 1;
35 $fw_mac_list = [ grep {defined and length} @$fw_mac_list ];
36  
37 my $bindarray = [ { sqlt_datatype => "array" }, $fw_mac_list ];
38  
39 my $macs
40 = schema(vars->{'tenant'})->resultset('Virtual::PortMacs')->search({},
41 { bind => [$bindarray, $bindarray], select => [ 'mac', 'ip' ], group_by => [ 'mac', 'ip' ] } );
42 my $cursor = $macs->cursor;
43 while ( my @vals = $cursor->next ) {
44 $port_macs->{ $vals[0] } = $vals[1];
45 }
46  
47 return $port_macs;
48 }
49  
50 1;