| 1 | package Net::DHCP::Info::Obj; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Net::DHCP::Info::Obj - Storage module for dhcp-information | ||||||||||
| 6 | |||||||||||
| 7 | =head1 VERSION | ||||||||||
| 8 | |||||||||||
| 9 | Version 0.01 | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This module contains methods that can access the data C<Net::DHCP::Info> | ||||||||||
| 14 | has extracted. It inherits from C<NetAddr::IP>, so it provides all the methods | ||||||||||
| 15 | from that package as well. | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | use Net::DHCP::Info::Obj; | ||||||||||
| 20 | |||||||||||
| 21 | my $ip = "127.0.0.1"; | ||||||||||
| 22 | my $obj = Net::DHCP::Info::Obj->new($ip); | ||||||||||
| 23 | |||||||||||
| 24 | $obj->mac("aa:b:02:3d:0:01"); | ||||||||||
| 25 | |||||||||||
| 26 | print $obj->mac; # prints the above mac | ||||||||||
| 27 | |||||||||||
| 28 | =cut | ||||||||||
| 29 | |||||||||||
| 30 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 5 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 5 | ▶ | use NetAddr::IP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 5 | our @ISA = qw/NetAddr::IP/; | |||||||||
| 36 | 5 | our $VERSION = '0.01'; | |||||||||
| 37 | 5 | our $AUTOLOAD; | |||||||||
| 38 | |||||||||||
| 39 | =head1 METHODS | ||||||||||
| 40 | |||||||||||
| 41 | =head2 binding | ||||||||||
| 42 | |||||||||||
| 43 | Returns the dhcp leases binding. | ||||||||||
| 44 | |||||||||||
| 45 | =head2 circuit_id | ||||||||||
| 46 | |||||||||||
| 47 | Returns the dhcp leases circuit id. | ||||||||||
| 48 | |||||||||||
| 49 | =head2 hostname | ||||||||||
| 50 | |||||||||||
| 51 | Returns the client-hostname | ||||||||||
| 52 | |||||||||||
| 53 | =head2 mac | ||||||||||
| 54 | |||||||||||
| 55 | Returns the dhcp leases mac. | ||||||||||
| 56 | |||||||||||
| 57 | =head2 range | ||||||||||
| 58 | |||||||||||
| 59 | Returns a list of ranges in a subnet in this format: | ||||||||||
| 60 | |||||||||||
| 61 | [$low_ip, $high_ip] | ||||||||||
| 62 | |||||||||||
| 63 | =head2 remote_id | ||||||||||
| 64 | |||||||||||
| 65 | Returns the dhcp leases remote id. | ||||||||||
| 66 | |||||||||||
| 67 | =head2 routers | ||||||||||
| 68 | |||||||||||
| 69 | Returns a list of routers in a subnet. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | 5 | ▶ | BEGIN { ## no critic # for strict | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||
| 74 | 5 | my @keys = qw/ | |||||||||
| 75 | circuit_id binding ends hostname | ||||||||||
| 76 | mac range remote_id routers starts | ||||||||||
| 77 | /; | ||||||||||
| 78 | |||||||||||
| 79 | 5 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 80 | |||||||||||
| 81 | 5 | for my $k (@keys) { | |||||||||
| 82 | 16 | ▶ | *$k = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 83 | 16 | my $self = shift; | |||||||||
| 84 | 16 | ▶ | $self->{$k} = $_[0] if(defined $_[0]); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 16 | $self->{$k}; | |||||||||
| 86 | } | ||||||||||
| 87 | 45 | } | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | =head2 add_range | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | 1 | ▶ | sub add_range { | ||||||||
|
Subroutine
add_range: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 95 | 1 | my $self = shift; | |||||||||
| 96 | 1 | my $range = shift; | |||||||||
| 97 | |||||||||||
| 98 | 1 | ▶ | return unless(ref $range eq 'ARRAY'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | |||||||||||
| 100 | 1 | push @{ $self->{'range'} }, $range; | |||||||||
| 101 | 1 | return; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | =head2 starts | ||||||||||
| 105 | |||||||||||
| 106 | =head2 starts_datetime | ||||||||||
| 107 | |||||||||||
| 108 | Returns the dhcp leases start time as string / DateTime object. | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | 1 | ▶ | sub starts_datetime { | ||||||||
|
Subroutine
starts_datetime: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 113 | 1 | my $self = shift; | |||||||||
| 114 | 1 | return $self->_datetime($self->starts); | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =head2 ends | ||||||||||
| 118 | |||||||||||
| 119 | =head2 ends_datetime | ||||||||||
| 120 | |||||||||||
| 121 | Returns the dhcp leases end time as string / DateTime object. | ||||||||||
| 122 | |||||||||||
| 123 | =cut | ||||||||||
| 124 | |||||||||||
| 125 | 0 | ▶ | sub ends_datetime { | ||||||||
|
Subroutine
ends_datetime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 126 | 0 | my $self = shift; | |||||||||
| 127 | 0 | return $self->_datetime($self->ends); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 1 | ▶ | sub _datetime { | ||||||||
|
Subroutine
_datetime: called CC=1 SCAR=0.0
| |||||||||||
| 131 | |||||||||||
| 132 | ### init | ||||||||||
| 133 | 1 | my $self = shift; | |||||||||
| 134 | 1 | my @time = split m"[\s\:/]"mx, shift; | |||||||||
| 135 | |||||||||||
| 136 | 1 | return DateTime->new( | |||||||||
| 137 | year => $time[0], | ||||||||||
| 138 | month => $time[1], | ||||||||||
| 139 | day => $time[2], | ||||||||||
| 140 | hour => $time[3], | ||||||||||
| 141 | minute => $time[4], | ||||||||||
| 142 | second => $time[5], | ||||||||||
| 143 | time_zone => 'UTC', | ||||||||||
| 144 | ); | ||||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | =head1 AUTHOR | ||||||||||
| 148 | |||||||||||
| 149 | Jan Henning Thorsen, C<< <pm at flodhest.net> >> | ||||||||||
| 150 | |||||||||||
| 151 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 152 | |||||||||||
| 153 | Copyright 2007 Jan Henning Thorsen, all rights reserved. | ||||||||||
| 154 | |||||||||||
| 155 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 156 | under the same terms as Perl itself. | ||||||||||
| 157 | |||||||||||
| 158 | =cut | ||||||||||
| 159 | |||||||||||
| 160 | 5 | 1; | |||||||||