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 β€” the source param is mostly the same as it is for Algorithm::Dependency. The one glow-up addition: as a source you can hand it an Algorithm::Dependency object, and the Algorithm::Dependency::Source for 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>


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