package Tk::IPEntry; #------------------------------------------------ # automagically updated versioning variables -- CVS modifies these! #------------------------------------------------ our $Revision = '$Revision: 1.9 $'; our $CheckinDate = '$Date: 2002/12/11 16:24:03 $'; our $CheckinUser = '$Author: xpix $'; # we need to clean these up right here $Revision =~ s/^\$\S+:\s*(.*?)\s*\$$/$1/sx; $CheckinDate =~ s/^\$\S+:\s*(.*?)\s*\$$/$1/sx; $CheckinUser =~ s/^\$\S+:\s*(.*?)\s*\$$/$1/sx; #------------------------------------------------- #-- package Tk::Graph ---------------------------- #------------------------------------------------- # ------------------------------------------------------- # # Tk/IPEntry.pm # # A Megawidget for Input Ip-Adresses Ipv4 and Ipv6 # =head1 NAME Tk::IPEntry - A megawidget for input of IP-Adresses IPv4 and IPv6 =head1 SYNOPSIS use Tk; use Tk::IPEntry; my $mw = MainWindow->new(); my $ipadress; my $entry = $mw->IPEntry( -variable => \$ipadress, )->pack(-side => 'left'); $ipadress = '129.2.32.1'; MainLoop; =cut # ------------------------------------------------------- # ------- S O U R C E ----------------------------------- # ------------------------------------------------------- use strict; use Carp; use Tk; use Tk::NumEntry; use Tk::HexEntry; use Tie::Watch; use Net::IP; # That's the Base use base qw/Tk::Frame/; # ... and construct the Widget! Construct Tk::Widget 'IPEntry'; # ------------------------------------------ sub ClassInit { # ------------------------------------------ # ClassInit is called once per MainWindow, and serves to # perform tasks for the class as a whole. Here we create # a Photo object used by all instances of the class. my ($class, $mw) = @_; $class->SUPER::ClassInit($mw); } # end ClassInit # ------------------------------------------ sub Populate { # ------------------------------------------ my ($obj, $args) = @_; my %specs; #------------------------------------------------- $obj->{type} = delete $args->{-type} || 'ipv4'; =head2 -type (I|ipv6) The format of Ip-Number. =cut #------------------------------------------------- =head1 METHODS Here come the methods that you can use with this Widget. =cut #------------------------------------------------- #------------------------------------------------- $specs{-variable} = [qw/METHOD variable Variable/, undef ]; =head2 $IPEntry->I(\$ipnumber); Specifies the name of a variable. The value of the variable is a text string to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the new value. The way in which the string is displayed in the widget depends on the particular widget and may be determined by other options, such as anchor or justify. =cut #------------------------------------------------- $specs{-set} = [qw/METHOD set Set/, undef]; =head2 $IPEntry->I($ipnumber); Set the IP number to display. You can use all standart format for IP-Adresses in Version 4 and Version 6. Here comes some examples, please look also in perldoc from Net::IP: A Net::IP object can be created from a single IP address: $ip->set('193.0.1.46') || die ... Or from a Classless Prefix (a /24 prefix is equivalent to a C class): $ip->set('195.114.80/24') || die ... Or from a range of addresses: $ip->set('20.34.101.207 - 201.3.9.99') || die ... Or from a address plus a number: $ip->set('20.34.10.0 + 255') || die ... The set() function accepts IPv4 and IPv6 addresses (it's necessary set -type option to 'ipv6'): $ip->set('dead:beef::/32') || die ... Very interesting feature, you can give Ip-Ranges and the user can only choice a Ip-Adress in this Range. The other Numbers is disabled. I.E.: $ip->set('195.114.80/24') || die ... $ip->set('dead:beef::/32') || die ... =cut #------------------------------------------------- $specs{-get} = [qw/METHOD get Get/, undef ]; =head2 $IPEntry->I(); Here you can get IP number from display. This is also a Interface to Net::IP, in example you will get the binary code from displayed IP-Number then you can call: $IPEntry->get('binip'); Please look for all allow commands to Net::IP. =cut #------------------------------------------------- $specs{-error} = [qw/METHOD error Error/, undef ]; =head2 $IPEntry->I(); This prints the last error. =cut # Ok, here the important structure from the widget .... $obj->SUPER::Populate($args); $obj->ConfigSpecs( -get => [qw/METHOD get Get/, undef ], -error => [qw/METHOD error Error/, undef ], %specs, ); # Widgets in the Megawidget # Next, we need 4 NumEntrys(ipv4) if(uc($obj->{type}) eq 'IPV4') { foreach my $n (0..3) { $obj->{nummer}->[$n] = $obj->NumEntry( -width => 3, -minvalue => 0, -maxvalue => 255, -bell => 1, )->pack( -side => 'left' ); # Bindings $obj->{nummer}->[$n]->bind('', sub { $obj->fullip } ); $obj->{nummer}->[$n]->bind('