Gtk2-Net-LDAP-Widgets

 view release on metacpan or  search on metacpan

Widgets/DistinguishedName.pm  view on Meta::CPAN

package Gtk2::Net::LDAP::Widgets::DistinguishedName;
#---[ pod head ]---{{{

=head1 NAME

Gtk2::Net::LDAP::Widgets::DistinguishedName - helper class for DN processing

=head1 SYNOPSIS

    This class is mostly used by other components to analyze and process LDAP 
    Distinguished Names and isn't meant to be used directly. Read the source in 
    case of any needs to do that.

=cut

#---}}}
use utf8;
use strict;
use vars qw(@ISA $VERSION);

use Net::LDAP;
use Net::LDAP::Util qw(ldap_explode_dn);
use Data::Dumper;

#@ISA = qw(Gtk2::TreeView);

our $VERSION = "2.0.1";

our $dntext;
our $dn;

use overload
q{""} => 'to_string';

# by OLO
# czw mar 17 17:51:34 CET 2005
# Constructor:
sub new {
  my $class = shift;
  my $self = {};
  $self->{dntext} = shift;
  $self->{dn} = _dn_normalize($self->{dntext});

  bless $self, $class;
}

# by OLO
# czw mar 17 17:51:20 CET 2005
# Conversion of self to string:
sub to_string {
  my $self  = shift;
  return $self->{dntext};
}

#---[ sub isDescendant ]---{{{

=head2 isDescendant

=over 4

=item isDescendant ( possible_ancestor )

Checks whether this DN is a child of another DN (possible_ancestor).

C<possible_ancestor> a distinguished name being tested for ancestorness in 
relation to current DN :)

=back

=cut
sub isDescendant($) {
  my $self  = shift;
  my $possible_ancestor = shift;
  my $mydn = $self->{dn};
  my $hisdn = $possible_ancestor->{dn};

  #print "Testing if $mydn is a child of $hisdn...\n";
  if (rindex($mydn, $hisdn) > 0) {
    #print "...it is.\n";
    return 1;
  } else {
    #print "...it isn't.\n";
    return 0;
  }
}
#---}}}

#---[ sub getRdn ]---{{{

=head2 getRdn

=over 4

=item getRdn ( possible_ancestor )

Returns the RDN of this DN in relation to a potential ancestor's DN ( the C<possible_ancestor> argument).
If the C<possible_ancestor> isn't an ancestor in fact, the returned RDN will be empty.

C<possible_ancestor> a distinguished name of potential ancestor

=back

=cut
sub getRdn($) {
  my $self  = shift;
  my $possible_ancestor = shift;
  if (! defined($possible_ancestor)) {
    $possible_ancestor = Gtk2::Net::LDAP::Widgets::DistinguishedName->new('');



( run in 2.486 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )