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

NAME

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

VERSION

9       version 1.111
10

SYNOPSIS

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

DESCRIPTION

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

TO DO

117       - Add support for non-naive weights via either custom code or method
118       name
119

SEE ALSO

121       Algorithm::Dependency, Algorithm::Dependency::Source
122

SUPPORT

124       Bugs may be submitted through the RT bug tracker
125       <https://rt.cpan.org/Public/Dist/Display.html?Name=Algorithm-
126       Dependency> (or bug-Algorithm-Dependency@rt.cpan.org <mailto:bug-
127       Algorithm-Dependency@rt.cpan.org>).
128

AUTHOR

130       Adam Kennedy <adamk@cpan.org>
131
133       This software is copyright (c) 2003 by Adam Kennedy.
134
135       This is free software; you can redistribute it and/or modify it under
136       the same terms as the Perl 5 programming language system itself.
137
138
139
140perl v5.30.1                      2020-01-29  Algorithm::Dependency::Weight(3)
Impressum