The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::vaporcalc::FormatString - Templated string formatter

SYNOPSIS

  my $things = "some very special";
  my $formatted = format_str( "My %string% with %this% var",
    this   => $things,
    string => "cool string",
  );  ## -> My cool string with some very special var

DESCRIPTION

A tiny string formatter.

Exports a single function: "format_str"

format_str

Takes a string and a hash (or hash reference) mapping template variables to replacement strings.

The replacement variables can be coderefs returning a string:

  format_str( "My string with %code",
    code => sub {
      my ($match, $orig, $callback) = @_;
      . . .
      return "Some string replacing variable $match"
    },
  );

The code reference will receive the matching variable ("code"), the original matched string ("%code" in the above example), and itself as its respective arguments.

AUTHOR

Jon Portnoy <avenj@cobaltirc.org>