File Coverage

blib/lib/Digest/Directory/API.pm
Criterion Covered Total %
statement 64 67 95.5
branch 30 48 62.5
condition 6 15 40.0
subroutine 12 13 92.3
pod 8 9 88.8
total 120 152 78.9


line stmt bran cond sub pod time code
1              
2             ######################################################################
3             #
4             # Directory Digest -- Digest::Directory::API.pm
5             # Matthew Gream (MGREAM)
6             # Copyright 2002 Matthew Gream. All Rights Reserved.
7             # $Id: API.pm,v 0.90 2002/10/21 20:24:06 matt Exp matt $
8             #
9             ######################################################################
10              
11             =head1 NAME
12              
13             Digest::Directory::API - api class for Directory Digests
14              
15             =head1 SYNOPSIS
16              
17             use Digest::Directory::API;
18            
19             my($d) = Digest::Directory::API->new();
20             $d->quiet(0);
21             $d->configure("/etc/dirgests.conf");
22             my($r) = $d->compare("", "", "", "/etc/dirgests.text", 0, 0);
23             ( $r > 0 ) && print "Warning: dirgests changed - inspect!\n";
24            
25             =head1 REQUIRES
26              
27             Perl 5.004, Digest::Directory::BASE.
28              
29             =head1 EXPORTS
30              
31             Nothing.
32              
33             =head1 DESCRIPTION
34              
35             B provides a more general API over
36             B that allows clients to configure,
37             create, show, compare and update directory digests.
38              
39             =cut
40              
41             ######################################################################
42              
43             package Digest::Directory::API;
44              
45             require 5.004;
46              
47 1     1   10357 use strict;
  1         3  
  1         40  
48 1     1   8 use warnings;
  1         3  
  1         41  
49 1     1   6 use vars qw( @ISA $PROGRAM $VERSION $AUTHOR $RIGHTS $USAGE );
  1         3  
  1         183  
50             @ISA = qw(Exporter);
51              
52             $PROGRAM = "Digest::Directory::API";
53             $VERSION = sprintf("%d.%02d", q$Revision: 0.90 $ =~ /(\d+)\.(\d+)/);
54             $AUTHOR = "Matthew Gream ";
55             $RIGHTS = "Copyright 2002 Matthew Gream. All Rights Reserved.";
56             $USAGE = "see pod documentation";
57              
58             ######################################################################
59              
60 1     1   752 use Digest::Directory::BASE;
  1         3  
  1         979  
61              
62             ######################################################################
63              
64             =head1 METHODS
65              
66             The following methods are provided:
67              
68             =over 4
69              
70             =cut
71              
72              
73             ######################################################################
74              
75             =item B<$dirgest = Digest::Directory::API-Enew( )>
76              
77             Create a dirgest instance; default configuration is set up, with
78             quiet = 0.
79              
80             =cut
81              
82             ######################################################################
83              
84             sub new
85             {
86 22     22 1 258381 my($class) = @_;
87              
88 22         140 my $self = {
89             quiet => 0,
90             dirgest => Digest::Directory::BASE->new()
91             };
92              
93 22         87 return bless $self, $class;
94             }
95              
96             sub dirgest
97             {
98 3     3 0 20 my($self) = @_;
99              
100 3         17 return $self->{'dirgest'};
101             }
102              
103              
104             ######################################################################
105              
106             =item B<$dirgest-Equiet( $enabled )>
107              
108             Enable quiet operating mode for a dirgest; ensures that no debug
109             trace output is provided during operation.
110              
111             $enabled => '0' or '1' for whether operation to be quiet or not;
112              
113             =cut
114              
115             ######################################################################
116              
117             sub quiet
118             {
119 22     22 1 178 my($self, $q) = @_;
120              
121 22 50       120 $self->{'quiet'} = $q if (defined $q);
122 22         89 $self->{'dirgest'}->quiet($self->{'quiet'});
123 22         40 return 1;
124             }
125              
126              
127             ######################################################################
128              
129             =item B<$dirgest-Etrim( $count )>
130              
131             Enable trim level, at specified count; all file/directory sets will
132             have their prefix trimmed.
133              
134             $count => 'n' where 'n' >= 0 && specifies the number of leading
135             components of a name to remove.
136              
137             =cut
138              
139             ######################################################################
140              
141             sub trim
142             {
143 0     0 1 0 my($self, $t) = @_;
144              
145 0         0 $self->{'dirgest'}->trim($t);
146 0         0 return 1;
147             }
148              
149              
150              
151             ######################################################################
152              
153             =item B<$result = $dirgest-Econfigure( $file, \@incl, \@excl )>
154              
155             Specify configuration for a dirgest;
156              
157             $file => filename to read configuration from in the format
158             as specified in Digest::Directory::BASE.pm;
159              
160             \@incl => array of file/directory sets to include (in addition
161             to those read from configuration file);
162              
163             \@excl => array of file/directory sets to exclude (in addition
164             to those read from configuration file);
165              
166             return => '1' on success, or '0' on failure;
167              
168             =cut
169              
170             ######################################################################
171              
172             sub configure
173             {
174 16     16 1 138 my($self, $conf, $incl, $excl) = @_;
175              
176 16 100       52 $self->{'dirgest'}->configure($conf)
177             if($conf);
178 16         45 foreach (@$incl)
179 15         62 { $self->{'dirgest'}->include($_); }
180 16         45 foreach (@$excl)
181 2         10 { $self->{'dirgest'}->exclude($_); }
182              
183 16         49 return 1;
184             }
185              
186              
187             ######################################################################
188              
189             =item B<$result = $dirgest-Ecreate( $link, $user, $pass, $file, $nodetails, $nosummary )>
190              
191             Create a dirgest and save to specified file;
192              
193             $link => the link to fetch dirgests from;
194              
195             $user => the http username to use with $link;
196              
197             $pass => the http password to use with $link;
198              
199             $file => the file to save dirgests to;
200              
201             $nodetails => don't show detail dirgests during activity;
202              
203             $nosummary => don't show summary dirgest during activity;
204              
205             return => '1' on success, or '0' on failure;
206              
207             =cut
208              
209             ######################################################################
210              
211             sub create
212             {
213 10     10 1 73 my($self, $link, $user, $pass, $file, $nodetails, $nosummary) = @_;
214              
215 10 50       33 print "CREATING\n"
216             if (!$self->{'quiet'});
217              
218 10 100       28 if ($link)
219             {
220 1 50       9 $self->{'dirgest'}->fetch($link, $user, $pass)
221             || return 0;
222             }
223             else
224             {
225 9 50       40 $self->{'dirgest'}->compute()
226             || return 0;
227             }
228              
229 10 100 66     59 $self->{'dirgest'}->print($nodetails, $nosummary)
230             unless ($nodetails && $nosummary);
231            
232 10 50 33     61 $file && $self->{'dirgest'}->save($file)
233             || return 0;
234              
235 10         39 return 1;
236             }
237              
238              
239             ######################################################################
240              
241             =item B<$result = $dirgest-Eshow( $link, $user, $pass, $nodetails, $nosummary )>
242              
243             Show a dirgest from a resource with options;
244              
245             $link => the link to fetch dirgests from;
246              
247             $user => the http username to use with $link;
248              
249             $pass => the http password to use with $link;
250              
251             $file => the file to save dirgests to;
252              
253             $nodetails => don't show detail dirgests during activity;
254              
255             $nosummary => don't show summary dirgest during activity;
256              
257             return => '1' on success, or '0' on failure;
258              
259             =cut
260              
261             ######################################################################
262              
263             sub show
264             {
265 2     2 1 18 my($self, $link, $user, $pass, $nodetails, $nosummary) = @_;
266              
267 2 50       8 print "SHOWING\n"
268             if (!$self->{'quiet'});
269              
270 2 100       6 if ($link)
271             {
272 1 50       5 $self->{'dirgest'}->fetch($link, $user, $pass)
273             || return 0;
274             }
275             else
276             {
277 1 50       6 $self->{'dirgest'}->compute()
278             || return 0;
279             }
280              
281 2 50 33     16 $self->{'dirgest'}->print($nodetails, $nosummary)
282             unless ($nodetails && $nosummary);
283              
284 2         8 return 1;
285             }
286              
287              
288             ######################################################################
289              
290             =item B<$result = $dirgest-Ecompare( $link, $user, $pass, $file, $nodetails, $nosummary, $showequal )>
291              
292             Compare dirgests as obtained from resources or locally;
293              
294             $link => the link to fetch dirgests from;
295              
296             $user => the http username to use with $link;
297              
298             $pass => the http password to use with $link;
299              
300             $file => the file to save dirgests to;
301              
302             $nodetails => don't show detail dirgests during activity;
303              
304             $nosummary => don't show summary dirgest during activity;
305              
306             $showequal => show equal dirgests during activity;
307              
308             return => '1' on success, or '0' on failure;
309              
310             =cut
311              
312             ######################################################################
313              
314             sub compare
315             {
316 4     4 1 35 my($self, $link, $user, $pass, $file, $nodetails, $nosummary, $showequal) = @_;
317              
318 4 50       15 print "COMPARING\n"
319             if (!$self->{'quiet'});
320              
321 4 100       11 if ($link)
322             {
323 2 50       10 $self->{'dirgest'}->fetch($link, $user, $pass)
324             || return 0;
325             }
326             else
327             {
328 2 50       14 $self->{'dirgest'}->compute()
329             || return 0;
330             }
331              
332 4         20 my $dirgest = Digest::Directory::BASE->new();
333 4         15 $dirgest->quiet($self->{'quiet'});
334 4 50       14 $dirgest->load($file)
335             || return 0;
336              
337 4         17 my ($result) = $self->{'dirgest'}->compare($dirgest,
338             $nodetails, $nosummary, $showequal);
339              
340 4         22 return $result;
341             }
342              
343              
344             ######################################################################
345              
346             =item B<$result = $dirgest-Eupdate( $link, $user, $pass, $file, $nodetails, $nosummary, $showequal )>
347              
348             Update a dirgest from a resource back to resource;
349              
350             $link => the link to fetch dirgests from;
351              
352             $user => the http username to use with $link;
353              
354             $pass => the http password to use with $link;
355              
356             $file => the file to save dirgests to;
357              
358             $nodetails => don't show detail dirgests during activity;
359              
360             $nosummary => don't show summary dirgest during activity;
361              
362             $showequal => show equal dirgests during activity;
363              
364             return => '1' on success, or '0' on failure;
365              
366             =cut
367              
368             ######################################################################
369              
370             sub update
371             {
372 2     2 1 18 my($self, $link, $user, $pass, $file, $nodetails, $nosummary, $showequal) = @_;
373              
374 2 50       9 print "UPDATING\n"
375             if (!$self->{'quiet'});
376              
377 2 100       7 if ($link)
378             {
379 1 50       8 $self->{'dirgest'}->fetch($link, $user, $pass)
380             || return 0;
381             }
382             else
383             {
384 1 50       6 $self->{'dirgest'}->compute()
385             || return 0;
386             }
387              
388 2         12 my $dirgest = Digest::Directory::BASE->new;
389 2         9 $dirgest->quiet($self->{'quiet'});
390 2 50 33     13 $file && $dirgest->load($file)
391             || return 0;
392              
393 2         11 my ($result) = $self->{'dirgest'}->compare($dirgest,
394             $nodetails, $nosummary, $showequal);
395              
396 2 50 33     16 $file && $self->{'dirgest'}->save($file)
397             || return 0;
398              
399 2         13 return 1;
400             }
401              
402              
403             ######################################################################
404              
405             =back
406              
407             =head1 AUTHOR
408              
409             Matthew Gream (MGREAM)
410              
411             =head1 VERSION
412              
413             Version 0.90.
414              
415             =head1 RIGHTS
416              
417             Copyright 2002 Matthew Gream. All Rights Reserved.
418              
419             This program is free software; you can redistribute it and/or modify
420             it under the same terms as Perl itself.
421              
422             =cut
423              
424             ######################################################################
425              
426             1;
427