1Algorithm::Dependency::UWseeirghCto(n3t)ributed Perl DocAulmgeonrtiatthimo:n:Dependency::Weight(3)
2
3
4

NAME

6       Algorithm::Dependency::Weight - Calculate dependency 'weights'
7

SYNOPSIS

9         # Create a source from a file
10         my $Source = Algorithm::Dependency::Source->new( 'file.txt' );
11
12         # Create a Weight algorithm object
13         my $alg = Algorithm::Dependency::Weight->new( source => $Source );
14
15         # Find the weight for a single item
16         my $weight = $alg->weight('foo');
17         print "The weight of 'foo' is $weight\n";
18
19         # Or a group
20         my $hash = $alg->weight_hash('foo', 'bar', 'baz');
21         print "The weight of 'foo', 'bar', and 'bar' are $hash->{foo},"
22             . " $hash->{bar} and $hash->{baz} respectively\n";
23
24         # Or all of the items
25         my $all = $alg->weight_all;
26         print "The following is a list from heaviest to lightest:\n";
27         foreach ( sort { $all->{$b} <=> $all->{$a} } keys %$all ) {
28             print "$_: $all->{$_}\n";
29         }
30

DESCRIPTION

32       In dependency systems, it can often be very useful to calculate an
33       aggregate or sum for one or all items. For example, to find the "naive
34       install weight" of a Perl distribution (where "naive" means you treat
35       each distribution equally), you would want the distribtion (1) + all
36       its dependencies (n) + all their dependencies (n2) recursively down‐
37       wards.
38
39       If calculated using a normal Algorithm::Dependency object, the result
40       would be (in a simple systems) equal to:
41
42         # Create your normal (non-ordered alg:dep)
43         my $dependency = Algorithm::Dependency->new( ... );
44
45         # Find the naive weight for an item
46         my $weight = scalar($dependency->schedule('itemname'));
47
48       "Algorithm::Dependency::Weight" provides a way of doing this with a
49       little more sophistication, and in a way that should work reasonable
50       well across all the Algorithm::Dependency family.
51
52       Please note that the this might be a little (or more than a little)
53       slower than it could be for the limited case of generating weights for
54       all of the items at once in a dependency system with no selected items
55       and no circular dependencies. BUT you can at least rely on this class
56       to do the job properly regardless of the particulars of the situation,
57       which is probably more important.
58
59       METHODS
60
61       new @params
62
63       The "new" constructor creates a new "Algorithm::Dependency::Weight"
64       object. It takes a number of key/value pairs as parameters (although at
65       the present time only one).
66
67       source => $Source
68           The "source" param is mostly the same as for Algorithm::Dependency.
69           The one addition is that as a source you can provide an Algo‐
70           rithm::Dependency object, and the Algorithm::Dependency::Source for
71           that will be used.
72
73       Returns a new "Algorithm::Dependency::Weight" object, or "undef" on
74       error.
75
76       source
77
78       The "source" accessor returns the source used for the weight calcula‐
79       tions.
80
81       This will be either the one passed to the constructor, or the source
82       from inside the "Algorithm::Dependency" object passed as the "source"
83       param (not the object itself, its source).
84
85       weight $name
86
87       The "weight" method takes the name of a single item and calculates its
88       weight based on the configuration of the "Algorithm::Depen‐
89       dency::Weight" object.
90
91       Returns the weight as a scalar (which in the naive case will be an
92       integer, but in more complex uses may be any real number), or "undef"
93       on error.
94
95       weight_hash @names
96
97       The "weight_hash" method takes a list of item names, and calculates
98       their weights.
99
100       Returns a reference to a "HASH" with the item names as keys and weights
101       as values, or "undef" on error.
102
103       weight_all
104
105       The "weight_all" method provides the one-shot method for getting the
106       weights of all items at once. Please note that this does not do any‐
107       thing different or special, but is slightly faster than iterating your‐
108       self.
109
110       Returns a reference to a "HASH" with the item names as keys and weights
111       as values, or "undef" on error.
112

TO DO

114       - Add support for non-naive weights via either custom code or method
115       name
116

SUPPORT

118       Bugs should be submitted via the CPAN bug tracker, located at
119
120       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Algorithm-Dependency>
121
122       For general comments, contact the author.
123

AUTHOR

125       Adam Kennedy <adamk@cpan.org>, <http://ali.as/>
126

SEE ALSO

128       Algorithm::Dependency, Algorithm::Dependency::Source
129
131       Copyright (c) 2003 - 2005 Adam Kennedy.
132
133       This program is free software; you can redistribute it and/or modify it
134       under the same terms as Perl itself.
135
136       The full text of the license can be found in the LICENSE file included
137       with this module.
138
139
140
141perl v5.8.8                       2008-01-14  Algorithm::Dependency::Weight(3)
Impressum