• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Text/H23-Jul-2005-23773

t/H23-Jul-2005-314233

ChangesH A D23-Jul-2005169 85

LICENSEH A D23-Jul-200520.1 KiB384309

MANIFESTH A D23-Jul-2005235 1312

META.ymlH A D23-Jul-2005348 1210

Makefile.PLH A D23-Jul-2005398 1310

READMEH A D23-Jul-20053.8 KiB132108

README

1NAME
2    Text::Outdent - Outdent chunks of text
3
4SYNOPSIS
5        my $foo = outdent($bar);
6
7        my $baz = outdent_quote(q{
8            this
9                is
10                a
11            string
12                that
13                is
14                indented
15            with
16                spaces
17                or
18                tab
19        });
20
21DESCRIPTION
22    This module was created to make it easy to have large chunks of strings
23    in the code. If you use a quote operator that spans over several lines
24    or a "here-doc" and have an indention of the code you get leading
25    whitespaces that you may or may not want. If you don't want them this
26    module easily removes them.
27
28    You can also use it for other texts that are indented.
29
30EXPORTED FUNCTIONS
31    No functions are exported by default. ":ALL" exports all.
32
33    "outdent($str)"
34        Removes the common leading whitespaces for each line. Currently
35        lines with only whitespaces are ignored and left untouched; treated
36        as blank lines if you like. No tab expansion is being performed; a
37        tab is just a whitespace character.
38
39        If the indention consists of both spaces and tabs then it's a good
40        idea to expand the tabs first, see &expand_leading_tabs. If the mix
41        of tabs and spaces is consistent, e.g. every line begins with
42        "  \t ", then that is recognized as indention.
43
44            # common leading whitespaces are removed.
45            my $str = <<'_STR_';
46                this
47                    is
48                    a
49                string
50                    that
51                    is
52                    indented
53                with
54                    spaces
55                    or
56                    tab
57            _STR_
58
59            print '* Indented: ', $str;
60            print '* Outdented: ', outdent($str);
61
62        outputs
63
64            * Indented:
65                this
66                    is
67                    a
68                string
69                    that
70                    is
71                    indented
72                with
73                    spaces
74                    or
75                    tab
76
77            * Outdented:
78            this
79                is
80                a
81            string
82                that
83                is
84                indented
85            with
86                spaces
87                or
88                tab
89
90    "outdent_all($str)"
91        Like &outdent except it doesn't treat "whitespace lines" as blank
92        lines.
93
94    "outdent_quote($str)"
95        Like &outdent but with some twists to make it smooth to use a
96        (possibly indented) quote operator spanning over several lines in
97        your source. The arrows (that isn't part of the code) below point
98        out the two issues this function takes care of.
99
100            my $foo = q{       <--- newline and possible spaces
101                foo
102                    bar
103                    baz
104                zip
105                    zap
106            };                 <--- empty line with possible spaces
107
108        First, all whitespaces uptil the first newline plus the newline
109        itself are removed. This takes care of the first issue.
110
111        Second, if the string ends with a newline followed by non-newline
112        whitespaces the non-newline whitespaces are removed. This takes care
113        of the second issue.
114
115        These fixes serve to make the quote operator's semantics equivalent
116        to a here-docs.
117
118    "expand_leading_tabs($tabstop, $str)"
119        Expands tabs that on a line only have whitespaces before them. Handy
120        to have if you have a file with mixed tab/space indention.
121
122AUTHOR
123    Johan Lodin <lodin@cpan.org>
124
125COPYRIGHT
126    Copyright 2004-2005 Johan Lodin. All rights reserved.
127
128    This library is free software; you can redistribute it and/or modify it
129    under the same terms as Perl itself.
130
131SEE ALSO
132