Net-DHCP-Info

 view release on metacpan or  search on metacpan

lib/Net/DHCP/Info/Obj.pm  view on Meta::CPAN

    my @keys = qw/
                   circuit_id binding ends hostname
                   mac range remote_id routers starts
               /;

    no strict 'refs';

    for my $k (@keys) {
        *$k = sub {
            my $self = shift;
            $self->{$k} = $_[0] if(defined $_[0]);
            $self->{$k};
        }
    }
}

=head2 add_range

=cut

sub add_range {
    my $self  = shift;
    my $range = shift;

    return unless(ref $range eq 'ARRAY');

    push @{ $self->{'range'} }, $range;
    return;
}

=head2 starts

=head2 starts_datetime

Returns the dhcp leases start time as string / DateTime object.

=cut

sub starts_datetime {
    my $self = shift;
    return $self->_datetime($self->starts);
}

=head2 ends

=head2 ends_datetime

Returns the dhcp leases end time as string / DateTime object.

=cut

sub ends_datetime {
    my $self = shift;
    return $self->_datetime($self->ends);
}

sub _datetime {

    ### init
    my $self = shift;
    my @time = split m"[\s\:/]"mx, shift;

    return DateTime->new(
        year      => $time[0],
        month     => $time[1],
        day       => $time[2],
        hour      => $time[3],
        minute    => $time[4],
        second    => $time[5],
        time_zone => 'UTC',
    );
}

=head1 AUTHOR

Jan Henning Thorsen, C<< <pm at flodhest.net> >>

=head1 COPYRIGHT & LICENSE

Copyright 2007 Jan Henning Thorsen, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1;



( run in 2.542 seconds using v1.01-cache-2.11-cpan-71847e10f99 )