---
name: "Arch::Util"
section: "3pm"
platform: "linux"
package: "libarch-perl"
version: "0.5.2-2"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/Arch::Util"
---

# Arch::Util(3pm)

Arch utility functions

## NAME

Arch::Util - Arch utility functions

## SYNOPSIS

```
    use Arch::Util qw(run_tla load_file save_file setup_config_dir);
    my $abrowse_output = run_tla('abrowse --summary --date --creator');
    my ($full_version) = run_tla('tree-version');
    my @full_revisions = run_tla('logs', '-r', '-f');
    my $cfg_dir = setup_config_dir(undef, "archipelago");
    my $content = load_file("$cfg_dir/versions.cfg");
    $content =~ s/^last_version = .*/last_version = $full_version/m;
    save_file("$cfg_dir/versions.cfg", $content);
```

## DESCRIPTION

A set of helper functions suitable for GNU Arch related projects in Perl.

Higher (object oriented) levels of Arch/Perl library make use of these helper functions.

## FUNCTIONS

The following functions are available:

**run\_tla**, **run\_cmd**, **run\_pipe\_from**, **load\_file**, **save\_file**, **copy\_dir**, **remove\_dir**, **setup\_config\_dir**, **standardize\_date**, **date2daysago**, **date2age**, **parse\_creator\_email**, **adjacent\_revision**.

The system functions die on errors.

- **is\_tla\_functional**

  Verify whether the system has a working arch backend installed (and possibly configured by environment variables, like TLA or ARCH\_BACKEND), needed for this perl library to function.

- **run\_tla** *subcommand\_with\_args*

  - **run\_tla** *subcommand* arg ...

  Run the given *tla* subcommand with optional arguments. Return the tla output in the scalar context, and a list of **chomp**-ed lines in the list context.

- **run\_cmd** *shell\_command\_with\_args*

  - **run\_cmd** *shell\_command* *arg* ...

  Run the given shell command (like *wc* or *awk*) with optional arguments. Return the command output in the scalar context, and a list of **chomp**-ed lines in the list context.

  **run\_tla** is implemented using **run\_cmd**.

- **run\_pipe\_from** *shell\_command\_with\_args*

  - **run\_pipe\_from** *shell\_command* *arg* ...

  Run the given shell command (like *ls* or *tar*) with optional arguments in the separate process. Return the pipe (file handle) that may be used to read the command output from.

  **run\_cmd** is implemented using **run\_pipe\_from**.

- **load\_file** *file\_name*

  - **load\_file** *file\_name* *scalar\_ref*

  - **load\_file** *file\_name* *array\_ref*

  Load the given *file\_name*. Return the file content if the returning value is expected. As a side effect, may modify the *scalar\_ref* or *array\_ref* if given, in the last case all file lines are split and **chomp**-ed.

- **save\_file** *file\_name* *content*

  Save the given *content* in the given *file\_name*. The *content* may be either scalar, scalar ref, or array ref (see **load\_file**).

- **copy\_dir** *dir1* *dir2*

  Copy *dir1* to *dir2* recursivelly, preserving as many attributes as possible.

- **remove\_dir** *dir* ..

  Remove *dir* (or dirs) recusivelly. Please be careful.

- **setup\_config\_dir**

  - **setup\_config\_dir** *dir*

  - **setup\_config\_dir** *dir* *subdir* ...

  Create (if needed) the configuration *dir* that defaults to either `$ARCH_MAGIC_DIR` or *~/.arch-magic* or */tmp/.arch-magic* if `$HOME` is unset.

  If one or more consecutive *subdir* given, repeat the same procedure for the sub-directory (including creating and diagnostics if needed).

  Return a name of the existing directory (including sub-directories if any).

- **standardize\_date** *default\_unix\_date\_string*

  Try to convert the given date string to "yyyy-mm-dd HH:MM:SS TMZ". If failed, the original string is returned.

- **date2daysago** *date\_string*

  Convert a date string to time difference to now in full days.

  In list content, return (num\_days\_ago, unix\_time, timezone\_str).

- **date2age** *date\_string*

  Like **date2daysago**, but return a human readable string, like "5 days" or "-6 weeks" or "7 months" or "3 years".

- **parse\_creator\_email** *my\_id*

  Try to parse the *arch* **my-id** of the patch creator. Return a list of his/her name and email.

- **adjacent\_revision** *full\_revision* *offset*

  Given the *full\_revision* and positive or negative offset, try to guess the full name of the adjacent revision.

## BUGS

Awaiting for your reports.

## AUTHORS

Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).

## SEE ALSO

For more information, see tla, Arch.
