Algori...:Weight(3pm)
π Algorithm::Dependency::Weight(3pm) β the manual, but make it make sense π
okay bestie, you found the Algori...:Weight(3pm) page (yes the manual name is literally truncated like that, it's giving mysterious β¨) and no cap, it's a Perl module about math-ing up how heavy stuff is in a dependency tree. Let's get into it. π
β¨ NAME β¨
Algorithm::Dependency::Weight β calculate dependency 'weights' π
πΈ VERSION πΈ
version 1.112
π¦ SYNOPSIS π¦
# Create a source from a file
my $Source = Algorithm::Dependency::Source->new( 'file.txt' );
# Create a Weight algorithm object
my $alg = Algorithm::Dependency::Weight->new( source => $Source );
# Find the weight for a single item
my $weight = $alg->weight('foo');
print "The weight of 'foo' is $weight\n";
# Or a group
my $hash = $alg->weight_hash('foo', 'bar', 'baz');
print "The weight of 'foo', 'bar', and 'bar' are $hash->{foo},"
. " $hash->{bar} and $hash->{baz} respectively\n";
# Or all of the items
my $all = $alg->weight_all;
print "The following is a list from heaviest to lightest:\n";
foreach ( sort { $all->{$b} <=> $all->{$a} } keys %$all ) {
print "$_: $all->{$_}\n";
}
π DESCRIPTION π
So in dependency systems β you know, the whole "this thing needs these things which need these other things" web πΈοΈ β it's super useful to work out an aggregate or a sum for one item, or for everything at once. Fr fr.
Case in point: the "naive install weight" of a Perl distribution. And when we say "naive", we mean you treat every single distribution exactly the same, no favorites, no main character energy π«Ά. So you'd want:
the distribution itself (1) + all its dependencies (n) + all their dependencies (n2), recursively downward, forever, until it stops. π
If you calculated that with a normal Algorithm::Dependency object, in a simple system the result would be this:
# Create your normal (non-ordered alg:dep)
my $dependency = Algorithm::Dependency->new( ... );
# Find the naive weight for an item
my $weight = scalar($dependency->schedule('itemname'));
But Algorithm::Dependency::Weight does the same job with a little more sophistication, and in a way that should work reasonably well across the entire Algorithm::Dependency family. obsessed. π
Heads up bestie: this might be a little (or more than a little) slower than it theoretically could be, but ONLY for the limited case of generating weights for all items at once, in a dependency system with no selected items and no circular dependencies. BUT β and this is the part that eats β you can at least rely on this class to do the job properly regardless of the particulars of the situation. Which is probably more important. periodt. π
π₯ METHODS π₯
new @params
The new constructor creates a brand new Algorithm::Dependency::Weight object. It takes a bunch of key/value pairs as params (though rn there's literally only one, iconic minimalism). β¨
source=>$Sourceβ thesourceparam is mostly the same as it is forAlgorithm::Dependency. The one glow-up addition: as a source you can hand it anAlgorithm::Dependencyobject, and theAlgorithm::Dependency::Sourcefor that object will get used instead. π
Returns a new Algorithm::Dependency::Weight object, or undef on error. π
source
The source accessor returns the source that's being used for the weight calculations. π
This will be either the one you passed to the constructor, or the source from inside the Algorithm::Dependency object you passed as the source param β and listen, it's not the object itself, it's its source. Important distinction, iykyk. π
weight $name
The weight method takes the name of a single item and calculates its weight based on how the Algorithm::Dependency::Weight object is configured. β¨
Returns the weight as a scalar (which in the naive case will be an integer, but in more complex uses can be any real number β she contains multitudes π), or undef on error.
weight_merged @names
The weight_merged method takes the name of a set of items and calculates an aggregated weight for the whole little squad. π«Ά
Returns the weight as a scalar, or undef on error.
weight_hash @names
The weight_hash method takes a list of item names and calculates all their weights. No cap. π¦
Returns a reference to a HASH with the item names as keys and the weights as values, or undef on error.
weight_all
The weight_all method is the one-shot girlboss method for getting the weights of every single item all at once. π
Please note: this does not do anything different or special, it's just slightly faster than iterating through them yourself. Efficiency queen. π
Returns a reference to a HASH with the item names as keys and the weights as values, or undef on error.
π TO DO π
- Add support for non-naive weights via either custom code or method name
π SEE ALSO π
Algorithm::Dependency, Algorithm::Dependency::Source
π SUPPORT π
Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Algorithm-Dependency> (or bug-Algorithm-Dependency@rt.cpan.org <mailto:bug-Algorithm-Dependency@rt.cpan.org>).
π AUTHOR π
Adam Kennedy <adamk@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2003 by Adam Kennedy.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole thing bestie, you're now officially fluent in dependency weights π this page came to you courtesy of perl v5.40.1, dated 2025-09-18 β and that's the vibe check, signing off! π¦β¨π
π¦ where this page comes from
- ubuntu resolute: libalgorithm-dependency-perl 1.112-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libalgorithm-dependency-perl 1.112-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms