line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::Dependency::MapReduce; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Algorithm::Dependency::MapReduce - A Map/Reduce implementation for Alg:Dep graphs |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
34469
|
use 5.006; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
93
|
|
17
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
18
|
2
|
|
|
2
|
|
25
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
228
|
|
19
|
2
|
|
|
2
|
|
14
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
20
|
2
|
|
|
2
|
|
2442
|
use Params::Util qw{ _CODE }; |
|
2
|
|
|
|
|
12714
|
|
|
2
|
|
|
|
|
245
|
|
21
|
2
|
|
|
2
|
|
3106
|
use Algorithm::Dependency (); |
|
2
|
|
|
|
|
16626
|
|
|
2
|
|
|
|
|
61
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
21
|
use vars qw{$VERSION @ISA}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10311
|
|
24
|
|
|
|
|
|
|
BEGIN { |
25
|
2
|
|
|
2
|
|
10
|
$VERSION = '0.03'; |
26
|
2
|
|
|
|
|
852
|
@ISA = 'Algorithm::Dependency'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
1
|
|
|
1
|
1
|
78
|
my $class = shift; |
31
|
1
|
|
|
|
|
6
|
my %args = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Check params |
34
|
1
|
50
|
|
|
|
7
|
unless ( _CODE($args{'map'}) ) { |
35
|
0
|
|
|
|
|
0
|
Carp::croak("The 'map' param is not a CODE reference"); |
36
|
|
|
|
|
|
|
} |
37
|
1
|
50
|
|
|
|
6
|
unless ( _CODE($args{'reduce'}) ) { |
38
|
0
|
|
|
|
|
0
|
Carp::croak("The 'reduce' param is not a CODE reference"); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Hand off to the parent constructor |
42
|
1
|
|
|
|
|
10
|
my $self = $class->SUPER::new(@_); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Add the extra attributes |
45
|
1
|
|
|
|
|
32
|
$self->{'map'} = $args{'map'}; |
46
|
1
|
|
|
|
|
3
|
$self->{'reduce'} = $args{'reduce'}; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
3
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub mapreduce { |
52
|
6
|
|
|
6
|
0
|
3799
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Fetch the dependencies for the provided params |
55
|
6
|
|
|
|
|
22
|
my $schedule = $self->schedule(@_); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Handle the special cases |
58
|
6
|
50
|
|
|
|
497
|
if ( @$schedule == 0 ) { |
59
|
|
|
|
|
|
|
# Empty list |
60
|
0
|
|
|
|
|
0
|
return undef; |
61
|
|
|
|
|
|
|
} |
62
|
6
|
100
|
|
|
|
15
|
if ( @$schedule == 1 ) { |
63
|
|
|
|
|
|
|
# Single element, just map it and return |
64
|
4
|
|
|
|
|
12
|
return $self->{'map'}->( $self, $schedule->[0] ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Map the first two elements and prime the reduction |
68
|
2
|
|
|
|
|
506
|
my $result = $self->{'reduce'}->( $self, |
69
|
|
|
|
|
|
|
scalar($self->{'map'}->( $self, shift(@$schedule) )), |
70
|
|
|
|
|
|
|
scalar($self->{'map'}->( $self, shift(@$schedule) )), |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Process the remaining elements |
74
|
2
|
|
|
|
|
20
|
while ( @$schedule ) { |
75
|
1
|
|
|
|
|
3
|
$result = $self->{'reduce'}->( $self, |
76
|
|
|
|
|
|
|
$result, |
77
|
|
|
|
|
|
|
scalar($self->{'map'}->( $self, shift(@$schedule) )), |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
9
|
return $result; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SUPPORT |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Bugs should be submitted via the CPAN bug tracker, located at |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
For general comments, contact the author. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Copyright 2009 Adam Kennedy. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This program is free software; you can redistribute |
109
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The full text of the license can be found in the |
112
|
|
|
|
|
|
|
LICENSE file included with this module. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |