NAME
String::Nudge - Indents all lines in a multi-line string
VERSION
Version 1.0002, released 2021-07-29.
SYNOPSIS
use
String::Nudge;
sub
out {
nudge
q{
A long
text.
}
;
}
# is exactly the same as
sub
out {
q{
A long
text.
}
;
}
DESCRIPTION
String::Nudge provides nudge
, a simple function that indents all lines in a multi line string.
METHODS
nudge $string
# ' hello'
my
$string
= nudge
'hello'
;
nudge $number_of_spaces, $string
# ' hello'
my
$string
= nudge 8,
'hello'
;
If $number_of_spaces
is not given (or isn't an integer >= 0) its default value is 4
.
Every line in $string
is indented by $number_of_spaces
. Lines only consisting of white space is trimmed (but not removed).
MORE EXAMPLES
Usage with qi
Syntax::Feature::Qi adds qi
and qqi
that removes the same amount of leading whitespace as the first (significant) line has from all lines in a string:
# these three packages are equivalent:
package
Example::Nudge {
sub
out {
nudge qi{
sub
funcname {
'stuff'
;
}
};
}
}
package
Example::Q {
sub
out {
q{
sub funcname {
print 'stuff';
}
};
}
}
package
Example::HereDoc {
sub
out {
(
my
$text
=
<<" END") =~ s{^ {8}}{}gm;
sub funcname {
print 'stuff';
}
END
$text
;
}
}
Usage with qs
Syntax::Feature::Qs adds qs
and qqs
that removes all leading whitespace from all lines in a string:
# these three packages are equivalent:
package
Example::Nudge {
sub
out {
nudge qs{
This is
a multi line
string.
};
}
}
package
Example::Q {
sub
out {
q{
This is
a multi line
string.
}
;
}
}
package
Example::HereDoc {
sub
out {
(
my
$text
=
<<" END") =~ s{^ {8}}{}gm;
This is
a multi line
string.
END
$text
;
}
}
SEE ALSO
SOURCE
https://github.com/Csson/p5-String-Nudge
HOMEPAGE
https://metacpan.org/release/String-Nudge
AUTHOR
Erik Carlsson <info@code301.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Erik Carlsson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.