Skip to content
Browse files

better param checking in the constructors

  • Loading branch information...
1 parent 8708fa5 commit 09a48a226c6301b76949c1a7dca38b6f30a0d4db @russoz committed
Showing with 11 additions and 3 deletions.
  1. +4 −1 lib/Net/LDAP/SimpleServer/LDIFStore.pm
  2. +7 −2 lib/Net/LDAP/SimpleServer/ProtocolHandler.pm
View
5 lib/Net/LDAP/SimpleServer/LDIFStore.pm
@@ -15,7 +15,7 @@ sub new {
my ( $class, $param ) = @_;
my $self = bless( { list => undef }, $class );
- return $self unless $param;
+ croak 'Must pass parameter' unless $param;
$self->load($param);
@@ -60,6 +60,9 @@ sub _open_ldif {
);
}
+ # Then, it must be a filename
+ croak q{Cannot find file "} . $param . q{"} unless -r $param;
+
return Net::LDAP::LDIF->new($param);
}
View
9 lib/Net/LDAP/SimpleServer/ProtocolHandler.pm
@@ -9,6 +9,8 @@ use fields qw(store);
use Carp;
use Net::LDAP::LDIF;
+use Scalar::Util qw{blessed};
+use UNIVERSAL::isa;
use version; our $VERSION = qv('0.0.10');
@@ -17,11 +19,14 @@ sub new {
my $store = shift;
my $self = $class->SUPER::new(@_);
+ croak 'Must pass store!' unless $store;
+ croak 'Not an object!' unless blessed($store);
+ croak 'Not a LDIFStore!'
+ unless $store->isa('Net::LDAP::SimpleServer::LDIFStore');
+
#printf "Accepted connection from: %s\n", $sock->peerhost();
$self->{store} = $store;
- croak 'Must pass store!' unless $store;
-
return $self;
}

0 comments on commit 09a48a2

Please sign in to comment.
Something went wrong with that request. Please try again.