LCC/Documents/module.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 37 SCAR 30.0
CC
4
Cov
0%
_new
6.0
method
6.0
next_document
6.0
CRAP 20.0
1 package LCC::Documents::module;
2  
3 # Make sure we do everything by the book
4 # Set modules to inherit from
5 # Set version information
6  
7 use strict;
8 @LCC::Documents::module::ISA = qw(LCC::Documents);
9 $LCC::Documents::module::VERSION = '0.01';
10  
11 # Return true value for use
12  
13 1;
14  
15 #------------------------------------------------------------------------
16  
17 # The following methods are class methods
18  
19 #------------------------------------------------------------------------
20  
21 # IN: 1 class of object
22 # 2 instantiated LCC object
23 # 3 instantated object to work with
24 # 4 method => value pairs to be executed
25 # OUT: 1 instantiated LCC::Documents::xxx object
26  
27 sub _new {
28  
29 # Obtain the class
30 # Obtain the LCC object
31 # Obtain the source (a blessed object)
32  
33 my $class = shift;
34 my $LCC = shift;
35 my $source = shift;
36  
37 # Add error if the source is not an object
38  
39 $LCC->_add_error( "$source is not an object" ) unless ref($source);
40  
41 # Create the object in the right way
42 # Save the source specification
43 # Return the object
44  
45 my $self = $class->SUPER::_new( $LCC,@_ );
46 $self->{'source'} = $source;
47 return $self;
48 } #_new
49  
50 #------------------------------------------------------------------------
51  
52 # The following methods change the object
53  
54 #------------------------------------------------------------------------
55  
56 # IN: 1 instantiated object
57 # 2 name of method to execute for "next_document"
58 # OUT: 1 current/old name of method
59  
60 sub method {
61  
62 # Obtain the method
63 # Remove the code ref of the method if we're changing
64 # Set/return the method name
65  
66 my $self = shift;
67 delete( $self->{'_method'} ) if @_;
68 $self->_variable( 'method',@_ );
69 } #method
70  
71 #------------------------------------------------------------------------
72  
73 # IN: 1 instantiated object
74 # OUT: 1 id of the next document
75 # 2 mtime of the next document
76 # 3 (optional) length of the next document
77 # 4 (optional) md5 of the next document
78 # 5 (optional) mimetype of the next document
79 # 6 (optional) subtype of the next document
80  
81 sub next_document {
82  
83 # Obtain the object
84 # If we don't have a code ref already
85 # Find out the method name to be used
86 # Create a code ref to the method needed
87 # Execute the method and return the result
88  
89 my $self = shift;
90 unless (exists( $self->{'_method'} )) {
91 my $method = $self->{'method'} || 'next_document';
92 $self->{'_method'} = \&{$self->{'source'}->$method};
93 }
94 return $self->{'_method'}->();
95 } #next_document
96  
97 #------------------------------------------------------------------------
98  
99 # The following subroutines deal with standard Perl features
100  
101 #------------------------------------------------------------------------
102  
103 __END__