lib/Net/LDAP/SimpleServer.pm

filter: Statementstmt 100% 85 / 85 Branchbran 81.2% 13 / 16 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 17 / 17 Podpod 100% 4 / 4 totaltotal 93.0% 121 / 130 CC 13 SCAR 8.8
CC
13
Cov
94%
post_configure_hook
4.0
process_request
4.0
import
3.0
CRAP 2.4
« lib/Net/LDAP/SimpleServer/LDIFStore.pm ↑ Summary blib/lib/Net/LDAP/SimpleServer/Constant.pm »
1 package Net::LDAP::SimpleServer;
2  
3 48 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Minimal-configuration, read-only LDAP server
7  
8 25 our $VERSION = '0.0.19'; # VERSION
9  
10 25 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 25 our $personality = undef;
14  
15 sub import {
16 47 ▶ my $pkg = shift;
Subroutine import: called CC=3 SCAR=11.1
17 47 ▶ $personality = shift || 'Fork';
Condition50%1/2
shift() || 'Fork'
l!l
047
MC/DC0%0/1
shift() || 'Fork'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
18  
19 24 ▶ eval "use base qw{Net::Server::$personality}"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
20 47 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 47 47
21  
22 47 push @Net::LDAP::SimpleServer::ISA, qw(Net::Server);
23  
24 #use Data::Dumper;
25 #print STDERR Data::Dumper->Dump( [ \@Net::LDAP::SimpleServer::ISA ],
26 # ['ISA'] );
27 47 return;
28 }
29  
30 25 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 25 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 25 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 25 ▶use File::Path 2.08 qw{make_path};
Subroutine BEGIN: called CC=1 SCAR=0.0
34 25 ▶use Scalar::Util qw{reftype};
Subroutine BEGIN: called CC=1 SCAR=0.0
35 25 ▶use Net::LDAP::SimpleServer::LDIFStore;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 25 ▶use Net::LDAP::SimpleServer::ProtocolHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 25 my $BASEDIR = File::Spec->catfile( home(), '.ldapsimple' );
39 25 my $DEFAULT_CONFIG_FILE = File::Spec->catfile( $BASEDIR, 'server.conf' );
40 25 my $DEFAULT_DATA_FILE = File::Spec->catfile( $BASEDIR, 'server.ldif' );
41 25 my $DEFAULT_LOG_FILE = File::Spec->catfile( $BASEDIR, 'server.log' );
42  
43 25 my @LDAP_PRIVATE_OPTIONS = ( 'store', 'input', 'output' );
44 24 my @LDAP_PUBLIC_OPTIONS = ( 'data_file', 'root_dn', 'root_pw', 'allow_anon' );
45  
46 24 make_path($BASEDIR);
47  
48 sub options {
49 39 ▶ my ( $self, $template ) = @_;
Subroutine options: called CC=3 SCAR=11.0
Pod documented
50 39 my $prop = $self->{server};
51  
52 ### setup options in the parent classes
53 39 $self->SUPER::options($template);
54  
55 ### add a single value option
56 39 for (@LDAP_PUBLIC_OPTIONS) {
57 156 ▶ $prop->{$_} = undef unless exists $prop->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $prop->{$_} 72 84 156
58 156 $template->{$_} = \$prop->{$_};
59 }
60  
61 #use Data::Dumper;
62 #print STDERR Data::Dumper->Dump( [$self->{server}], ['server'] );
63 39 return;
64 }
65  
66 sub default_values {
67 33 ▶ my $self = @_;
Subroutine default_values: called CC=3 SCAR=11.1
Pod documented
68  
69 33 my $v = {};
70 33 $v->{port} = 389;
71 33 $v->{log_file} = $DEFAULT_LOG_FILE;
72 33 ▶ $v->{conf_file} = $DEFAULT_CONFIG_FILE if -r $DEFAULT_CONFIG_FILE;
Branch: 1 branch
BranchTrueFalseTotal
if -r $DEFAULT_CONFIG_FILE 0 33 33
73 $v->{syslog_ident} =
74 33 'Net::LDAP::SimpleServer [' . $Net::LDAP::SimpleServer::VERSION . ']';
75  
76 33 $v->{allow_anon} = 1;
77 33 $v->{root_dn} = 'cn=root';
78 33 ▶ $v->{data_file} = $DEFAULT_DATA_FILE if -r $DEFAULT_DATA_FILE;
Branch: 1 branch
BranchTrueFalseTotal
if -r $DEFAULT_DATA_FILE 0 33 33
79  
80 #use Data::Dumper; print STDERR Dumper($v);
81 33 return $v;
82 }
83  
84 sub post_configure_hook {
85 18 ▶ my $self = shift;
Subroutine post_configure_hook: called CC=4 SCAR=14.0
Pod documented
86 18 my $prop = $self->{server};
87  
88 # create server directory in home dir
89 18 make_path($BASEDIR);
90  
91 #use Data::Dumper; print STDERR '# ' . Dumper( $prop );
92 croak q{Configuration has no "data_file" file!}
93 18 ▶ unless $prop->{data_file};
Branch: 1 branch
BranchTrueFalseTotal
unless $prop->{"data_file"} 4 14 18
94 croak qq{Cannot read data_file file (} . $prop->{data_file} . q{)}
95 14 ▶ unless -r $prop->{data_file};
Branch: 1 branch
BranchTrueFalseTotal
unless -r $prop->{"data_file"} 1 13 14
96  
97 # data_file is not a "public" option in the server, it is created here
98 $prop->{store} =
99 Net::LDAP::SimpleServer::LDIFStore->new( $prop->{data_file} )
100 13 ▶ || croak q{Cannot create data store!};
Condition33%1/3
'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'}) || croak('Cannot create data store!')
l!l&&r!l&&!r
1300
MC/DC0%0/2
'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'}) || croak('Cannot create data store!')
'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'}) croak('Cannot create data store!')
Truth table33%1/3
A || B
A= 'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'})B= croak('Cannot create data store!')
ABresult
1X1
011
000
101  
102 13 return;
103 }
104  
105 sub process_request {
106 6 ▶ my $self = shift;
Subroutine process_request: called CC=4 SCAR=13.9
Pod documented
107 6 my $prop = $self->{server};
108  
109 6 my $params = { map { ( $_ => $prop->{$_} ) } @LDAP_PUBLIC_OPTIONS };
110 6 for (@LDAP_PRIVATE_OPTIONS) {
111 18 ▶ $params->{$_} = $prop->{$_} if $prop->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $prop->{$_} 6 12 18
112 }
113 6 $params->{sock} = $self->{server}->{client};
114 7 my $handler = Net::LDAP::SimpleServer::ProtocolHandler->new($params);
115  
116 7 ▶ until ( $handler->handle ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handler->handle) 14 6 20
117  
118 # intentionally empty loop
119 }
120 7 return;
121 }
122  
123 24 1; # Magic true value required at end of module
124  
125 __END__
« lib/Net/LDAP/SimpleServer/LDIFStore.pm ↑ Summary blib/lib/Net/LDAP/SimpleServer/Constant.pm »