File Coverage

blib/lib/Net/LDAP/Constant.pm
Criterion Covered Total %
statement 5 26 19.2
branch 3 24 12.5
condition 0 3 0.0
subroutine 2 3 66.6
pod 2 2 100.0
total 12 58 20.6


line stmt bran cond sub pod time code
1             # Copyright (c) 1998-2009 Graham Barr . All rights reserved.
2             # This program is free software; you can redistribute it and/or
3             # modify it under the same terms as Perl itself.
4              
5             package Net::LDAP::Constant;
6              
7             our $VERSION = '0.23';
8              
9 26     26   70495 use Exporter qw(import);
  26         74  
  26         15472  
10              
11             my @err2name;
12              
13             local $_;
14             while () {
15             last if /^=cut/;
16             my $protocol_const = /^=head2 Protocol Constants/ ... /^=head2/;
17             next unless /^=item\s+(LDAP_\S+)\s+\((.*)\)/;
18             my ($name, $value) = ($1, $2);
19             *{$name} = sub () { $value };
20             push @EXPORT_OK, $name;
21             $err2name[$value] = $name if $protocol_const;
22             }
23              
24              
25             # These subs are really in Net::LDAP::Util, but need to access
26             # so its easier for them to be here.
27              
28              
29             sub Net::LDAP::Util::ldap_error_name {
30 98 50   98 1 28360 my $code = 0 + (ref($_[0]) ? $_[0]->code : $_[0]);
31              
32 98 100       446 $err2name[$code] || sprintf('LDAP error code %d(0x%02X)', $code, $code);
33             }
34              
35              
36             sub Net::LDAP::Util::ldap_error_text {
37 0 0   0 1   my $code = 0 + (ref($_[0]) ? $_[0]->code : $_[0]);
38 0           my $text;
39              
40 0           seek(DATA, 0, 0);
41 0           local $/=''; # paragraph mode
42 0           local $_;
43 0           my $n = -1;
44 0           while () {
45 0 0 0       last if /^=head2/ and ++$n;
46 0 0         last if /^=cut/;
47 0 0         next if $n;
48 0 0         if (/^=item\s+(LDAP_\S+)\s+\((\d+)\)/) {
    0          
49 0 0         last if defined $text;
50 0 0         $text = '' if $2 == $code;
51             }
52             elsif (defined $text) {
53 0           $text .= $_;
54             }
55             }
56              
57 0 0         if (defined $text) {
58             # Do some cleanup. Really should use a proper pod parser here.
59              
60 0           $text =~ s/^=item\s+\*\s+/ * /msg;
61 0           $text =~ s/^=(over\s*\d*|back)//msg;
62 0           $text =~ s/ +\n//g;
63 0           $text =~ s/\n\n+/\n\n/g;
64 0 0         $text =~ s/\n+\Z/\n/ if defined $text;
65             }
66              
67 0           return $text;
68             }
69              
70             1;
71              
72             __DATA__