Minor style cleanups, version bump. v1.3.0
authorMahlon E. Smith <mahlon@laika.com>
Thu, 04 Dec 2014 14:15:09 -0800
changeset 73 b3b840a4b56c
parent 72 39e9f802eb40
child 74 ceb8bd75e05b
Minor style cleanups, version bump.
shelldap
--- a/shelldap	Wed Dec 03 09:47:26 2014 +0100
+++ b/shelldap	Thu Dec 04 14:15:09 2014 -0800
@@ -476,8 +476,8 @@
 	$self->{'API'}->{'match_uniq'} = 0;
 
 	$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi';
-	$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less';
-	$self->{'env'}	= [ qw/ debug cacheage timeout / ];
+	$self->{'pager'}  = $conf->{'pager'}  || $ENV{'PAGER'}  || 'less';
+	$self->{'env'}	  = [ qw/ debug cacheage timeout / ];
 
 	# let autocomplete work with the '=' character
 	my $term = $self->term();
@@ -667,6 +667,7 @@
 	}
 
 	# ldif -> stdout
+	#
 	else {
 		$self->{'ldif'} = Net::LDAP::LDIF->new( \*STDOUT, 'w', sort => 1, wrap => $self->wrapsize );
 	}
@@ -803,6 +804,74 @@
 }
 
 
+### Emit LDIF to the terminal.
+###
+sub display
+{
+	my $self  = shift;
+	my $dn    = shift;
+	my @attrs = @{;shift};
+	my $use_pager = shift;
+
+	unless ( $dn ) {
+		print "No dn provided.\n";
+		return;
+	}
+
+	# support '.'
+	$dn = $self->base() if $dn eq '.';
+
+	# support globbing
+	#
+	my $s;
+	if ( $dn eq '*' ) {
+		$s = $self->search({
+			scope  => 'one',
+			vals   => 1,
+			attrs  => \@attrs
+		});
+	}
+	elsif ( $dn =~ /\*/ ) {
+		$s = $self->search({
+			scope  => 'one',
+			vals   => 1,
+			filter => $dn,
+			attrs  => \@attrs
+		});
+	}
+
+	# absolute/relative dn
+	#
+	else {
+		$dn = $self->path_to_dn( $dn );
+		$s = $self->search({
+			base   => $dn,
+			vals   => 1,
+			attrs  => \@attrs
+		});
+	}
+
+	# emit error, if any
+	#
+	if ( $s->{'code'} ) {
+		print $s->{'message'} . "\n";
+		return;
+	}
+
+	# display to stdout or pager
+	#
+	my $ldif = $self->ldif( $use_pager );
+	foreach my $e ( @{ $s->{'entries'} } ) {
+		$ldif->write_entry( $e );
+	}
+	if( $use_pager ) {
+		system( $self->{'pager'}, $self->{'ldif_fname'} );
+		unlink $self->{'ldif_fname'};
+	}	
+	return;
+}
+
+
 ### Perform an LDAP search.
 ###
 ### Returns a hashref containing the return code and
@@ -1129,8 +1198,8 @@
 		my $sub = "comp_$_";
 		*$sub   = \&autocomplete_cwd;
 	}
-	*comp_touch   = \&comp_create;
-	*comp_export  = \&comp_setenv;
+	*comp_touch  = \&comp_create;
+	*comp_export = \&comp_setenv;
 
 	# setup alias subs
 	#
@@ -1202,80 +1271,19 @@
 	my $dn    = shift;
 	my @attrs = (@_) ? @_ : ('*');
 
-	display($self, $dn, \@attrs, 0);
+	$self->display( $dn, \@attrs, 0 );
 }
 
+
+### Display an entry as LDIF to the terminal with external pagination.
+###
 sub run_less
 {
 	my $self  = shift;
 	my $dn    = shift;
 	my @attrs = (@_) ? @_ : ('*');
 
-	display($self, $dn, \@attrs, 1);
-}
-
-sub display{
-	my $self  = shift;
-	my $dn    = shift;
-	my @attrs = @{;shift};
-	my $use_pager = shift;
-
-	unless ( $dn ) {
-		print "No dn provided.\n";
-		return;
-	}
-
-	# support '.'
-	$dn = $self->base() if $dn eq '.';
-
-	# support globbing
-	#
-	my $s;
-	if ( $dn eq '*' ) {
-		$s = $self->search({
-			scope  => 'one',
-			vals   => 1,
-			attrs  => \@attrs
-		});
-	}
-	elsif ( $dn =~ /\*/ ) {
-		$s = $self->search({
-			scope  => 'one',
-			vals   => 1,
-			filter => $dn,
-			attrs  => \@attrs
-		});
-	}
-
-	# absolute/relative dn
-	#
-	else {
-		$dn = $self->path_to_dn( $dn );
-		$s = $self->search({
-			base   => $dn,
-			vals   => 1,
-			attrs  => \@attrs
-		});
-	}
-
-	# emit error, if any
-	#
-	if ( $s->{'code'} ) {
-		print $s->{'message'} . "\n";
-		return;
-	}
-
-	# display to stdout or pager
-	#
-	my $ldif = $self->ldif($use_pager);
-	foreach my $e ( @{ $s->{'entries'} } ) {
-		$ldif->write_entry( $e );
-	}
-	if($use_pager) {
-		system( $self->{'pager'}, $self->{'ldif_fname'} );
-		unlink $self->{'ldif_fname'};
-	}	
-	return;
+	$self->display( $dn, \@attrs, 1 );
 }
 
 
@@ -2278,7 +2286,7 @@
 use warnings;
 
 $0 = 'shelldap';
-my $VERSION = '1.2.0';
+my $VERSION = '1.3.0';
 
 use Getopt::Long;
 use YAML::Syck;