@Onis::Users::EXPORT_OK =
(qw(
- ident_to_name chatter_to_name name_to_ident
+ chatter_to_name
+ name_to_chatter name_to_ident name_to_nick
get_realname get_link get_image
));
@Onis::Users::ISA = ('Exporter');
=cut
our $Users = {};
-our $IdentToName = {};
-our $NameToIdent = {};
-
+our $ChatterToName = {};
+our $NameToChatter = {};
my $VERSION = '$Id$';
print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
=over 4
-=item B<ident_to_name> (I<$ident>)
+=item B<chatter_to_name> (I<$chatter>)
-Matches the ident against the configured hostmasks. Uses caching to
-speed up execution. Returns the name or an empty string if not found.
+Passes the ident-part of I<$chatter> to B<ident_to_name>.
=cut
-sub ident_to_name
+sub chatter_to_name
{
- my $ident = shift;
- my $name = '';
+ my $chatter = shift;
+ my $retval = '';
- if (defined ($IdentToName->{$ident}))
+ if (defined ($ChatterToName->{$chatter}))
{
- $name = $IdentToName->{$ident};
+ return ($ChatterToName->{$chatter});
}
- else
+
+ USER: for (keys %$Users)
{
- USER: for (keys (%$Users))
+ my $name = $_;
+ for (@{$Users->{$name}{'host'}})
{
- my $this_name = $_;
- for (@{$Users->{$this_name}{'host'}})
- {
- my $host_re = $_;
+ my $re = $_;
- if ($ident =~ $host_re)
- {
- $name = $this_name;
- last (USER);
- }
+ if ($chatter =~ $re)
+ {
+ $retval = $_;
+ last USER;
}
}
+ }
- if (($::DEBUG & 0x1000) and $name)
- {
- print STDERR $/, __FILE__, ": Host ``$ident'' belongs to ``$name''";
- }
+ if (($::DEBUG & 0x1000) and $retval)
+ {
+ print STDERR $/, __FILE__, ": ``$chatter'' identified as ``$retval''";
}
-
- $IdentToName->{$ident} = $name;
- $NameToIdent->{$name} = $ident if ($name);
- return ($name);
+
+ $ChatterToName->{$chatter} = $retval;
+ $NameToChatter->{$retval} = $chatter if ($retval);
+
+ return ($retval);
}
-=item B<chatter_to_name> (I<$chatter>)
+=item B<name_to_chatter> (I<$name>)
-Passes the ident-part of I<$chatter> to B<ident_to_name>.
+Returns the most recent chatter for I<$name>.
=cut
-sub chatter_to_name
+sub name_to_chatter
{
- my $chatter = shift;
- my ($nick, $ident) = split (m/!/, $chatter);
+ my $name = shift;
- return (ident_to_name ($ident));
+ if (defined ($NameToChatter->{$name}))
+ {
+ return ($NameToChatter->{$name});
+ }
+ else
+ {
+ return ('');
+ }
}
=item B<name_to_ident> (I<$name>)
-Does the reverse of B<ident_to_name>: Returns the most recent association of
-I<$name> to an ident. This function should rarely be needed..
+Returns the most recent ident for I<$name>.
=cut
{
my $name = shift;
- if (defined ($NameToIdent->{$name}))
+ if (defined ($NameToChatter->{$name}))
+ {
+ my $chatter = $NameToChatter->{$name};
+ my ($nick, $ident) = split (m/!/, $chatter);
+
+ return ($ident);
+ }
+ else
+ {
+ return ('');
+ }
+}
+
+=item B<name_to_nick> (I<$name>)
+
+Returns the most recent nick for I<$name>.
+
+=cut
+
+sub name_to_nick
+{
+ my $name = shift;
+
+ if (defined ($NameToChatter->{$name}))
{
- return ($NameToIdent->{$name});
+ my $chatter = $NameToChatter->{$name};
+ my ($nick, $ident) = split (m/!/, $chatter);
+
+ return ($nick);
}
else
{