---
name: "UR::Util"
section: "3pm"
platform: "linux"
package: "libur-perl"
version: "0.470+ds-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/UR::Util"
---

# UR::Util(3pm)

Collection of utility subroutines and methods

- path\_relative\_to

  ```
    $rel_path = UR::Util::path_relative_to($base, $target);
  ```

  Returns the pathname to `$target` relative to `$base`.  If `$base` and `$target` are the same, then it returns '.'.  If `$target` is a subdirectory of of `$base`, then it returns the portion of `$target` that is unique compared to `$base`.  If `$target` is not a subdirectory of `$base`, then it returns a relative pathname starting with `$base`.

- generate\_readwrite\_methods

  ```
    UR::Util->generate_readwrite_methods
    (
        some_scalar_property => 1,
        some_array_property => []
    );
  ```

  This method generates accessor/set methods named after the keys of its hash argument.  The type of function generated depends on the default value provided as the hash key value.  If the hash key is a scalar, a scalar method is generated.  If the hash key is a reference to an array, an array method is generated.

  This method does not overwrite class methods that already exist.

- generate\_readwrite\_methods\_override

  ```
    UR::Util->generate_readwrite_methods_override
    (
        some_scalar_property => 1,
        some_array_property => []
    );
  ```

  Same as generate\_readwrite\_function except that we force the functions into the namespace even if the function is already defined

- generate\_readonly\_methods

  ```
    UR::Util->generate_readonly_methods
    (
        some_scalar_property => 1,
        some_array_property => []
    );
  ```

  This method generates accessor methods named after the keys of its hash argument.  The type of function generated depends on the default value provided as the hash key value.  If the hash key is a scalar, a scalar method is generated.  If the hash key is a reference to an array, an array method is generated.

  This method does not overwrite class methods that already exist.

- object

  ```
    my $o = UR::Util::object($something);
  ```

  Return the object form of the supplied argument.  For regular objects, it returns the argument unchanged.  For singleton class names, it returns the instance of the Singleton.  For other class names, it throws an exception.

- mapreduce\_grep

  ```
      my @matches = UR::Util->map_reduce_grep { shift->some_test } @candidates;
  ```

  Works similar to the Perl `"grep"` builtin, but in a possibly-parallel fashion. If the environment variable UR\_NR\_CPU is set to a number greater than one, it will fork off child processes to perform the test on slices of the input list, collect the results, and return the matching items as a list.

  The test function is called with a single argument, an item from the list to be tested, and should return a true of false value.

## NAME

UR::Util - Collection of utility subroutines and methods

## DESCRIPTION

This package contains subroutines and methods used by other parts of the  infrastructure.  These subs are not likely to be useful to outside code.
