| 1 | #!/bin/false | ||||||||||
| 2 | # ABSTRACT: PD Exclude option (code 67) -- prefix to exclude from IA_PD | ||||||||||
| 3 | # PODNAME: Net::DHCPv6::Option::PdExclude | ||||||||||
| 4 | 15 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | package Net::DHCPv6::Option::PdExclude; | ||||||||||
| 7 | 15 | $Net::DHCPv6::Option::PdExclude::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_PD_EXCLUDE | ||||||||||
| 12 | 15 | ); | |||||||||
| 13 | 15 | ▶ | use Net::DHCPv6::X::Truncated (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 15 | ▶ | use Net::DHCPv6::X::BadOption (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 15 | ▶ | use parent 'Net::DHCPv6::Option'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 15 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 15 | my $BYTE_ALIGN_MASK = 7; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||
| 19 | 15 | my $BYTE_SHIFT = 3; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||
| 20 | |||||||||||
| 21 | 9 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 22 | 9 | my ( $class, %args ) = @_; | |||||||||
| 23 | 9 | ▶ | croak 'PdExclude requires prefix_length' unless defined $args{prefix_length}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 8 | my $addr = $class->_pick_addr( \%args, 'address' ); | |||||||||
| 25 | 8 | ▶ | croak 'PdExclude requires address' unless defined $addr; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 7 | my $addr_len = ( $args{prefix_length} + $BYTE_ALIGN_MASK ) >> $BYTE_SHIFT; | |||||||||
| 27 | 7 | $addr = substr( $addr, 0, $addr_len ); | |||||||||
| 28 | 7 | $args{code} = $OPTION_PD_EXCLUDE; | |||||||||
| 29 | 7 | $args{data} = pack( 'C', $args{prefix_length} ) . $addr; | |||||||||
| 30 | 7 | my $self = $class->SUPER::new( %args ); | |||||||||
| 31 | 7 | $self->{prefix_length} = $args{prefix_length}; | |||||||||
| 32 | 7 | $self->{address} = $addr; | |||||||||
| 33 | 7 | return bless $self, $class; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 6 | ▶ | sub prefix_length { return shift->{prefix_length} } | ||||||||
|
Subroutine
prefix_length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 5 | ▶ | sub address_raw { return shift->{address} } | ||||||||
|
Subroutine
address_raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | 4 | ▶ | sub address { return shift->{address} } | ||||||||
|
Subroutine
address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 39 | |||||||||||
| 40 | 3 | ▶ | sub from_bytes_inner { | ||||||||
|
Subroutine
from_bytes_inner: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 41 | 3 | my ( $class, $code, $payload ) = @_; | |||||||||
| 42 | 3 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated PdExclude option' ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | if CORE::length( $payload ) < 1; | ||||||||||
| 44 | 3 | my $plen = unpack( 'C', substr( $payload, 0, 1 ) ); | |||||||||
| 45 | 3 | my $addr_len = ( $plen + $BYTE_ALIGN_MASK ) >> $BYTE_SHIFT; | |||||||||
| 46 | 3 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated PdExclude address' ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | if 1 + $addr_len > CORE::length( $payload ); | ||||||||||
| 48 | 3 | my $addr = substr( $payload, 1, $addr_len ); | |||||||||
| 49 | 3 | return $class->new( prefix_length => $plen, address_raw => $addr ); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 2 | ▶ | sub as_bytes { | ||||||||
|
Subroutine
as_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 53 | 2 | my $self = shift; | |||||||||
| 54 | 2 | my $payload = pack( 'C', $self->{prefix_length} ) . $self->{address}; | |||||||||
| 55 | 2 | return pack( 'nn', $self->{code}, CORE::length( $payload ) ) . $payload; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 15 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_PD_EXCLUDE} = __PACKAGE__; | |||||||||
| 59 | 15 | 1; | |||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||