| 1 | #!/bin/false | ||
| 2 | # ABSTRACT: Elapsed Time option (code 8) -- 16-bit centiseconds | ||
| 3 | # PODNAME: Net::DHCPv6::Option::ElapsedTime | ||
| 4 | use strictures 2; | ||
| 5 | |||
| 6 | package Net::DHCPv6::Option::ElapsedTime; | ||
| 7 | $Net::DHCPv6::Option::ElapsedTime::VERSION = '0.002'; | ||
| 8 | use Net::DHCPv6::OptionList; | ||
| 9 | use Carp qw( croak ); | ||
| 10 | use Net::DHCPv6::Constants; | ||
| 11 | use Net::DHCPv6::X::BadOption; | ||
| 12 | use parent 'Net::DHCPv6::Option'; | ||
| 13 | use namespace::clean; | ||
| 14 | |||
| 15 | sub new { | ||
| 16 | my ( $class, %args ) = @_; | ||
| 17 | croak 'ElapsedTime requires centiseconds' unless defined $args{centiseconds}; | ||
| 18 | $args{code} = $OPTION_ELAPSED_TIME; | ||
| 19 | $args{data} = pack( 'n', $args{centiseconds} ); | ||
| 20 | my $self = $class->SUPER::new( %args ); | ||
| 21 | $self->{centiseconds} = $args{centiseconds}; | ||
| 22 | return bless $self, $class; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub centiseconds { return shift->{centiseconds} } | ||
| 26 | |||
| 27 | sub from_bytes_inner { | ||
| 28 | my ( $class, $code, $payload ) = @_; | ||
| 29 | Net::DHCPv6::X::BadOption->throw( message => 'ElapsedTime option must be exactly 2 bytes' ) | ||
| 30 | if CORE::length( $payload ) != 2; | ||
| 31 | my $cs = unpack( 'n', $payload ); | ||
| 32 | return $class->new( centiseconds => $cs ); | ||
| 33 | } | ||
| 34 | |||
| 35 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_ELAPSED_TIME} = __PACKAGE__; | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | __END__ |