Lukas Mai > Quote-Code-0.03 > Quote::Code

Download:
Quote-Code-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.03   Source   Latest Release: Quote-Code-1.01

NAME ^

Quote::Code - quoted strings with arbitrary code interpolation

SYNOPSIS ^

 use Quote::Code;
 print qc"2 + 2 = {2 + 2}";  # "2 + 2 is 4"
 my $msg = qc{The {$obj->name()} is {$obj->state()}.};
 
 my $heredoc = qc_to <<'EOT';
 .trigger:hover .message:after {
   content: "The #{get_adjective()} brown fox #{get_verb()} over the lazy dog.";
 }
 EOT
 print $heredoc;

DESCRIPTION ^

This module provides the new keywords qc and qc_to.

qc

qc is a quoting operator like q or qq. It works like q in that it doesn't interpolate $foo or @foo, but like qq in that it recognizes backslash escapes such as \n, \xff, etc.

What it adds is the ability to embed arbitrary expressions in braces ({...}). This is both more readable and more efficient than the old "foo @{[bar]}" trick. All embedded code runs in scalar context.

If you need a literal { in a qc string, you can escape it with a backslash (\{) or interpolate code that yields a left brace ({'{'}).

qc_to

For longer strings you can use qc_to, which provides a heredoc-like syntax. The main difference between qc and qc_to is that qc_to uses the Ruby-like #{ ... } to interpolate code (not { ... }). This is because { } are more common in longer texts and escaping them gets annoying.

qc_to has two syntactic forms:

 qc_to <<'FOO'
 ...
 FOO

and

 qc_to <<"FOO"
 ...
 FOO

After qc_to there must always be a << (this is to give syntax highlighters a chance to get things right). After that, there are two possibilities:

Variables aren't interpolated in either case.

BUGS ^

It doesn't understand \N{...}.

AUTHOR ^

Lukas Mai, <l.mai at web.de>

COPYRIGHT & LICENSE ^

Copyright 2012 Lukas Mai.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

syntax highlighting: