lib/Net/DHCPv6/Option/VendorClass.pm

filter: Statementstmt 100% 58 / 58 Branchbran 70.0% 7 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 91.2% 83 / 91 CC 8 SCAR 10.0
CC
8
Cov
92%
new
5.2
from_bytes_inner
4.0
BEGIN
1.0
CRAP 2.7
« lib/Net/DHCPv6/Option/Auth.pm ↑ Summary lib/Net/DHCPv6/Option/IAAddr.pm »
1 #!/bin/false
2 # ABSTRACT: Vendor Class option (code 16) -- enterprise-number + opaque data
3 # PODNAME: Net::DHCPv6::Option::VendorClass
4 15 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::DHCPv6::Option::VendorClass;
7 15 $Net::DHCPv6::Option::VendorClass::VERSION = '0.003';
8 15 ▶use Net::DHCPv6::OptionList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Net::DHCPv6::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 $OPTION_VENDOR_CLASS
12 15 );
13 15 ▶use Net::DHCPv6::X::Truncated ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use parent 'Net::DHCPv6::Option';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use Ref::Util qw( is_plain_arrayref );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 my $EMPTY = q();
18 15 my $ENT_NUM_LEN = 4; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
19  
20 9 ▶sub new {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
21 9 my ( $class, %args ) = @_;
22 9 ▶ croak 'VendorClass requires enterprise_number' unless defined $args{enterprise_number};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"enterprise_number"} 1 8 9
23 8 $args{code} = $OPTION_VENDOR_CLASS;
24 8 ▶ my $data_list = $args{vendor_data} // $args{data} // [];
Condition40%2/5
($args{"vendor_data"} // $args{"data"}) // []
l!l
80
$args{"vendor_data"} // $args{"data"}
l!l&&r!l&&!r
800
MC/DC0%0/2
($args{"vendor_data"} // $args{"data"}) // []
$args{"vendor_data"} $args{"data"}
Truth table33%1/3
A // B
A= $args{"vendor_data"}B= $args{"data"}
ABresult
1X1
011
000
25 8 ▶ $data_list = [$data_list] unless is_plain_arrayref( $data_list );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_arrayref($data_list) 0 8 8
26 my $encoded =
27 8 pack( 'N', $args{enterprise_number} ) . join( $EMPTY, map { pack( 'n', CORE::length ) . $_ } @{$data_list} );
28 8 $args{data} = $encoded;
29 8 my $self = $class->SUPER::new( %args );
30 8 $self->{enterprise_number} = $args{enterprise_number};
31 8 $self->{vendor_data} = $data_list;
32 8 return bless $self, $class;
33 }
34  
35 4 ▶sub enterprise_number { return shift->{enterprise_number} }
Subroutine enterprise_number: called CC=1 SCAR=0.0
Pod documented
36 3 ▶sub vendor_data { return shift->{vendor_data} }
Subroutine vendor_data: called CC=1 SCAR=0.0
Pod documented
37  
38 6 ▶sub from_bytes_inner {
Subroutine from_bytes_inner: called CC=4 SCAR=13.9
Pod documented
39 6 my ( $class, $code, $payload ) = @_;
40 6 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated VendorClass option' )
Branch: 1 branch
BranchTrueFalseTotal
if length $payload < $ENT_NUM_LEN 0 6 6
41 if CORE::length( $payload ) < $ENT_NUM_LEN;
42 6 my $en = unpack( 'N', substr( $payload, 0, $ENT_NUM_LEN ) );
43 6 my $rest = substr( $payload, $ENT_NUM_LEN );
44 6 my @items;
45 6 my $offset = 0;
46 6 my $len = CORE::length( $rest );
47 6 ▶ while ( $offset + 2 <= $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset + 2 <= $len) 7 6 13
48 7 my $ilen = unpack( 'n', substr( $rest, $offset, 2 ) );
49 7 $offset += 2;
50 7 ▶ Net::DHCPv6::X::Truncated->throw( message => 'Truncated VendorClass data item' )
Branch: 1 branch
BranchTrueFalseTotal
if $offset + $ilen > $len 0 7 7
51 if $offset + $ilen > $len;
52 7 push @items, substr( $rest, $offset, $ilen );
53 7 $offset += $ilen;
54 }
55 6 return $class->new( enterprise_number => $en, vendor_data => \@items );
56 }
57  
58 15 $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_VENDOR_CLASS} = __PACKAGE__;
59 15 1;
60  
61 __END__
« lib/Net/DHCPv6/Option/Auth.pm ↑ Summary lib/Net/DHCPv6/Option/IAAddr.pm »