DNS-ZoneSerialNumber

 view release on metacpan or  search on metacpan

lib/DNS/ZoneSerialNumber.pm  view on Meta::CPAN

        croak 'Invalid serial (must be numeric, positive, non-zero, and <= ' . SERIAL_MAX . ')';
    }
}

sub __check_valid_serial {
    my ( $serial ) = @_;
    if (   ( !defined $serial )
        || ( $serial !~ /^\d+$/ )
        || ( $serial > SERIAL_MAX )
        || ( $serial == 0 ) )
    {
        return 0;
    }
    return 1;
}

sub __check_valid_increment_and_croak {
    my ( $serial ) = @_;
    if (   ( !defined $serial )
        || ( $serial !~ /^\d+$/ )
        || ( $serial > INCREMENT_MAX ) )
    {
        croak 'Invalid amount (must be numeric, positive, and <= ' . INCREMENT_MAX . ')';
    }
}

sub _compare {
    my ( $self, $i2, $swapped ) = @_;
    my $i1;

    if ( ref $i2 eq 'DNS::ZoneSerialNumber' ) {
        $i2 = $i2->serial;
    }
    __check_valid_serial_and_croak( $i2 );

    if ( $swapped ) {
        $i1 = $i2;
        $i2 = $self->{serial};
    } else {
        $i1 = $self->{serial};
    }

    if ( $i1 == $i2 ) { return 0; }

    # Logic taken from RFC 1982 (I know it's not pretty but it's meant to
    # resemble the RFC).
    if (   ( $i1 < $i2 && $i2 - $i1 < SERIAL_HALF )
        || ( $i1 > $i2 && $i1 - $i2 > SERIAL_HALF ) )
    {
        return -1;
    }

    if (   ( $i1 < $i2 && $i2 - $i1 > SERIAL_HALF )
        || ( $i1 > $i2 && $i1 - $i2 < SERIAL_HALF ) )
    {
        return 1;
    }
    # As per RFC 1982 there are value pairs that can not be logically compared.
    # They are neither less than, greater than, nor equal to, each other. If we
    # encounter one of these pairs, simply return undef. <=> returns undef when
    # comparing against NaN, so returning undef from a compare function is not
    # completely unheard of.
    return undef;
}

sub _copy {
    my ( $self ) = @_;
    return DNS::ZoneSerialNumber->new( $self->serial );
}

=head2 valid

Accepts a single parameter, the serial number to test for validity.

Returns true or false depending representing whether or not the specified
serial number represents a valid serial number. Valid serial numbers are
positive integers between 1 and SERIAL_MAX (inclusive). See L<CONSTANTS> for
details.

Note: This method may be called statically or as an instance method.

=cut

sub valid {
    my ( $self, $serial ) = @_;
    if ( !ref $self ) {
        $serial = $self;
    }
    if ( ref $serial eq 'DNS::ZoneSerialNumber' ) {
        $serial = $serial->serial;
    }
    return __check_valid_serial( $serial );
}

=head2 serial

Accepts no parameters. Returns the represented serial number as a Perl scalar.

Note: In string or numeric context, a DNS::ZoneSerialNumber object will return
an appropriate representation of its serial number automatically.

=cut

sub serial {
    my ( $self ) = @_;
    return $self->{serial};
}

=head2 set

Accepts a single parameter, the new serial number. Returns the
DNS::ZoneSerialNumber object with the updated serial number.

Sets the serial number represented by the object to the specified serial
number. If the specified serial number is invalid the method will L<croak>.

=cut

sub set {
    my ( $self, $newval ) = @_;
    if ( ref $newval eq 'DNS::ZoneSerialNumber' ) {



( run in 1.366 second using v1.01-cache-2.11-cpan-39bf76dae61 )