Name

App::Sqitch::ItemFormatter - Format events and changes for command output

Synopsis

  my $formatter = App::Sqitch::ItemFormatter->new(%params);
  say $formatter->format($format, $item);

Description

This class is used by commands to format items for output. For example, "log" uses it to format the events it finds. It uses String::Formatter to do the actual formatting, but configures it for all the various times of things typically displayed, such as change names, IDs, event types, etc. This keeps things relatively simple, as all one needs to pass to "format()" is a format and then a hash reference of values to be used in the format.

Interface

Constructor

"new"
  my $formatter = App::Sqitch::ItemFormatter->new(%params);
Constructs and returns a formatter object. The supported parameters are:
"abbrev"
Instead of showing the full 40-byte hexadecimal change ID, format as a partial prefix the specified number of characters long.
"date_format"
Format to use for timestamps. Defaults to "iso". Allowed values:
"iso"
"iso8601"
ISO-8601 format.
"rfc"
"rfc2822"
RFC-2822 format.
"full"
"long"
"medium"
"short"
A format length to pass to the system locale's "LC_TIME" category.
"raw"
Raw format, which is strict ISO-8601 in the UTC time zone.
"strftime:$string"
An arbitrary "strftime" pattern. See "strftime Paterns" in DateTime for comprehensive documentation of supported patterns.
"cldr:$pattern"
An arbitrary "cldr" pattern. See "CLDR Paterns" in DateTime for comprehensive documentation of supported patterns.
"color"
Controls the use of ANSI color formatting. The value may be one of:
"auto" (the default)
"always"
"never"
"formatter"
A String::Formatter object. You probably don't want to pass one of these, as the default one understands all the values to that Sqitch is likely to want to format.

Instance Methods

"format"
  $formatter->format( $format, $item );
Formats an item as a string and returns it. The item will be formatted using the first argument. See "Formats" for the gory details.
The second argument is a hash reference defining the item to be formatted. These are simple key/value pairs, generally identifying attribute names and values. The supported keys are:
"event"
The type of event, which is one of:
"deploy"
"revert"
"fail"
"project"
The name of the project with which the change is associated.
"change_id"
The change ID.
"change"
The name of the change.
"note"
A brief description of the change.
"tags"
An array reference of the names of associated tags.
"requires"
An array reference of the names of any changes required by the change.
"conflicts"
An array reference of the names of any changes that conflict with the change.
"committed_at"
An App::Sqitch::DateTime object representing the date and time at which the event was logged.
"committer_name"
Name of the user who deployed the change.
"committer_email"
Email address of the user who deployed the change.
"planned_at"
An App::Sqitch::DateTime object representing the date and time at which the change was added to the plan.
"planner_name"
Name of the user who added the change to the plan.
"planner_email"
Email address of the user who added the change to the plan.

Formats

The format argument to "format()" specifies the item information to be included in the resulting string. It works a little bit like "printf" format and a little like Git log format. For example, this format:
  format:The committer of %h was %{name}c%vThe title was >>%s<<%v
Would show something like this:
  The committer of f26a3s was Tom Lane
  The title was >>We really need to get this right.<<
The placeholders are:
%H: Event change ID
%h: Event change ID (respects "--abbrev")
%n: Event change name
%o: Event change project name
"%($len)h": abbreviated change of length $len
%e: Event type (deploy, revert, fail)
%l: Localized lowercase event type label
%L: Localized title case event type label
%c: Event committer name and email address
"%{name}c": Event committer name
"%{email}c": Event committer email address
"%{date}c": commit date (respects "--date-format")
"%{date:rfc}c": commit date, RFC2822 format
"%{date:iso}c": commit date, ISO-8601 format
"%{date:full}c": commit date, full format
"%{date:long}c": commit date, long format
"%{date:medium}c": commit date, medium format
"%{date:short}c": commit date, short format
"%{date:cldr:$pattern}c": commit date, formatted with custom CLDR pattern
"%{date:strftime:$pattern}c": commit date, formatted with custom strftime pattern
%c: Change planner name and email address
"%{name}p": Change planner name
"%{email}p": Change planner email address
"%{date}p": plan date (respects "--date-format")
"%{date:rfc}p": plan date, RFC2822 format
"%{date:iso}p": plan date, ISO-8601 format
"%{date:full}p": plan date, full format
"%{date:long}p": plan date, long format
"%{date:medium}p": plan date, medium format
"%{date:short}p": plan date, short format
"%{date:cldr:$pattern}p": plan date, formatted with custom CLDR pattern
"%{date:strftime:$pattern}p": plan date, formatted with custom strftime pattern
%t: Comma-delimited list of tags
"%{$sep}t": list of tags delimited by $sep
%T: Parenthesized list of comma-delimited tags
"%{$sep}T": Parenthesized list of tags delimited by $sep
%s: Subject (a.k.a. title line)
%r: Comma-delimited list of required changes
"%{$sep}r": list of required changes delimited by $sep
%R: Localized label and list of comma-delimited required changes
"%{$sep}R": Localized label and list of required changes delimited by $sep
%x: Comma-delimited list of conflicting changes
"%{$sep}x": list of conflicting changes delimited by $sep
%X: Localized label and list of comma-delimited conflicting changes
"%{$sep}X": Localized label and list of conflicting changes delimited by $sep
%b: Body
%B: Raw body (unwrapped subject and body)
"%{$prefix}"B: Raw body with $prefix prefixed to every line
"%{event}_" Localized label for "event"
"%{change}_" Localized label for "change"
"%{committer}_" Localized label for "committer"
"%{planner}_" Localized label for "planner"
"%{by}_" Localized label for "by"
"%{date}_" Localized label for "date"
"%{committed}_" Localized label for "committed"
"%{planned}_" Localized label for "planned"
"%{name}_" Localized label for "name"
"%{project}_" Localized label for "project"
"%{email}_" Localized label for "email"
"%{requires}_" Localized label for "requires"
"%{conflicts}_" Localized label for "conflicts"
%v vertical space (newline)
"%{$color}C": An ANSI color: black, red, green, yellow, reset, etc.
"%{:event}C": An ANSI color based on event type (green deploy, blue revert, red fail)
"%{$attribute}a": The raw attribute name and value, if it exists and has a value

See Also

sqitch-log
Documentation for the "log" command to the Sqitch command-line client.
sqitch
The Sqitch command-line client.

Author

David E. Wheeler <[email protected]>

License

Copyright (c) 2012-2022 iovation Inc., David E. Wheeler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Questions & Answers

Helpful answers and articles about App::Sqitch::ItemFormatter you may found on these sites:
Stack Overflow Server Fault Super User Unix & Linux Ask Ubuntu Network Engineering DevOps Raspberry Pi Webmasters Google Search