line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LDAP::Batch::Action::Add; |
2
|
3
|
|
|
3
|
|
22
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
107
|
|
3
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
96
|
|
4
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
268
|
|
5
|
3
|
|
|
3
|
|
23
|
use base qw( Net::LDAP::Batch::Action ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
2076
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( dn attr )); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Net::LDAP::Batch::Action::Add - add entry to LDAP server |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Net::LDAP::Batch::Action::Add; |
18
|
|
|
|
|
|
|
my $action = Net::LDAP::Batch::Action->new( |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
ldap => $net_ldap_object, |
21
|
|
|
|
|
|
|
dn => 'name=foo,dc=company,dc=com', |
22
|
|
|
|
|
|
|
attr => [ |
23
|
|
|
|
|
|
|
name => 'foo', |
24
|
|
|
|
|
|
|
mail => 'foo@company.com' |
25
|
|
|
|
|
|
|
], |
26
|
|
|
|
|
|
|
}); |
27
|
|
|
|
|
|
|
$action->execute or $action->rollback; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This is a base class for batch actions. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
B Net::LDAP::Batch::Action objects will croak() if anything |
35
|
|
|
|
|
|
|
unusual happens. This approach assumes that Catastrophic Failure is a |
36
|
|
|
|
|
|
|
Good Thing. So use eval() if you need to catch exceptions. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 init |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Overrides base method to confirm that dn() and attr() are set. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub init { |
47
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
48
|
1
|
|
|
|
|
20
|
$self->SUPER::init(@_); |
49
|
1
|
50
|
|
|
|
11
|
if ( !$self->dn ) { |
50
|
0
|
|
|
|
|
0
|
croak "dn required"; |
51
|
|
|
|
|
|
|
} |
52
|
1
|
50
|
33
|
|
|
19
|
if ( !$self->attr |
|
|
|
33
|
|
|
|
|
53
|
|
|
|
|
|
|
or !ref( $self->attr ) |
54
|
|
|
|
|
|
|
or ref( $self->attr ) ne 'ARRAY' ) |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
|
|
0
|
croak "attr array ref required"; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
45
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 execute |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Creates a Net::LDAP::Entry object, adds the dn() and attr() |
64
|
|
|
|
|
|
|
values to it, then adds to the LDAP server. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub execute { |
69
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
70
|
1
|
50
|
|
|
|
7
|
if ( $self->complete ) { |
71
|
0
|
|
|
|
|
0
|
croak "action already flagged as complete"; |
72
|
|
|
|
|
|
|
} |
73
|
1
|
50
|
|
|
|
12
|
my $dn = $self->dn or croak "dn required"; |
74
|
1
|
50
|
|
|
|
9
|
my $attr = $self->attr or croak "attr required"; |
75
|
|
|
|
|
|
|
|
76
|
1
|
50
|
|
|
|
9
|
carp "adding $dn: " . Data::Dump::dump($attr) if $self->debug; |
77
|
1
|
|
|
|
|
43
|
my $entry = Net::LDAP::Entry->new; |
78
|
1
|
|
|
|
|
57
|
$entry->dn($dn); |
79
|
1
|
|
|
|
|
37
|
$entry->add(@$attr); |
80
|
1
|
|
|
|
|
82
|
my $msg = $self->ldap->add($entry); |
81
|
1
|
50
|
|
|
|
20810
|
if ( $msg->code ) { |
82
|
0
|
|
|
|
|
0
|
croak "failed to add $dn: " . $self->get_ldap_err($msg); |
83
|
|
|
|
|
|
|
} |
84
|
1
|
|
|
|
|
23
|
$self->entry($entry); |
85
|
1
|
|
|
|
|
9
|
$self->complete(1); |
86
|
1
|
|
|
|
|
40
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 rollback |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Deletes the entry added in execute(). |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub rollback { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
0
|
0
|
|
|
|
|
return 0 unless $self->complete; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
my $dn = $self->dn or croak "dn required to rollback"; |
100
|
0
|
0
|
|
|
|
|
carp "rolling back $dn" if $self->debug; |
101
|
0
|
|
|
|
|
|
my $msg = $self->ldap->delete($dn); |
102
|
0
|
0
|
|
|
|
|
if ( $msg->code ) { |
103
|
0
|
|
|
|
|
|
croak "failed to rollback $dn: " . $self->get_ldap_err($msg); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$self->complete(0); |
107
|
0
|
|
|
|
|
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |