Text-Autoformat-1.74/000755 000765 000024 00000000000 12626343224 014750 5ustar00neilbstaff000000 000000 Text-Autoformat-1.74/Changes000644 000765 000024 00000015404 12626343224 016247 0ustar00neilbstaff000000 000000 Revision history for Perl module Text::Autoformat 1.74 2015-11-28 NEILB - On Perl 5.22+ you could get "Negative repeat count does nothing" warnings. Thanks to SREZIC for RT#109838. - Made the mention of Text::Reform in SEE ALSO be a link. Thanks to MANWAR for the PR doing this. - Added some more entries to SEE ALSO. 1.73 2015-11-08 NEILB - Fixed warnings about uninitialized values in Hang.pm GH#4. Thanks to Jeremy Mates for the PR. - Changed github repo URL after changing my github username 1.72 2015-06-14 NEILB - Switched to Dist::Zilla, dropping both Build.PL and Makefile.PL -- phew! - Refactored the two cuckoo packages into separate modules, Text::Autoformat::Hang and Text::Autoformat::NullHang. 1.71_01 2015-06-06 NEILB - The changes released in 1.72 (above) were first done in a developer release. 1.71 2015-05-04 NEILB - Previous release had a problem with PAUSE, caused by the two internal packages not having a $VERSION. Identified and reported as PAUSE issue GH#170 by KENTNL++. Added $VERSION to internal packages. 1.70 2015-05-01 NEILB - Removed useless loading of utf8 and Data::Dumper. RJBS++ - Only renumber ASCII-digit lists, don't touch other \d things. RJBS++ 1.69_01 2015-04-25 NEILB - This was a developer release containing the changes subsequently released in 1.70 (see above). 1.69 2015-02-15 NEILB - Changed the internal packages Hang and NullHang to Text::Autoformat::Hang and Text::Autoformat::NullHang respectively. 1.68 2015-02-15 NEILB - Was failing on input of an empty string RT#101994. Fix from DCONWAY. Apologies for the confusion caused by Damian and I both releasing, this release should straighten things up. - Fixed syntax errors in Quoting section of doc. DCONWAY++ 1.67 2015-01-08 NEILB - Got co-maint from Damian so I could put the dist on github. Thanks Damian! - Reformatted this file as per CPAN::Changes::Spec - Added github repo to metadata and doc 1.669006 2014-10-03 DCONWAY - Improved 'quoter' option to allow augmenting quoter regex, rather than just replacing it (thanks Peter) 1.669005 2014-10-03 DCONWAY - Added Lisp-style leading ; as a quoter (thanks Roland) - Added 'quoter' option to allow user to specify a regex to be used to recognize quoters (thanks Peter) 1.669004 2013-07-31 DCONWAY - Tweaked widow handling to avoid a nasty edge case (thanks Michael!) 1.669003 2013-05-13 DCONWAY - Unknown changes 1.669002 2010-06-22 DCONWAY - Patched missing case in 'ignore' option handling (thanks Alan) 1.669001 2010-05-30 DCONWAY - Added major improvements to the 'ignore' option (thanks Dan!) 1.668001 2010-04-03 DCONWAY - Removed spurious debugging statement in bad Pod. (Thanks Chris) 1.666.0 2009-04-16 DCONWAY - No changes logged 1.14.0 2007-09-29 DCONWAY - Fixed bug in handling empty mail messages - Fixed bug in handling sig delimiters - Fixed bug in paragraph ignoring code (thanks Rob) - Fixed bug in handling whitespace-only input (thanks Ed) - Fixed bug in Roman numerals (thanks Suresh) - Fixed overeager autocentering (thanks Suresh) - Enhanced 'lists' option to allow only specific types of lists to be recognized (thanks Rob) - Fixed bug in numbered hangs (thanks Rob) - Fixed bug in Roman numeraled hangs (thanks Rob) - Fixed misidentification of 8:20-style times as leading numbers (thanks Rob) - Fixed sentence mode (thanks Eric) - Changed licence to "same terms as Perl itself" to improve Fedora compatibility 1.13 2005-05-04 DCONWAY - Added sample config files for emacs and vim - Extended allows "Name>" quoters to "Name_1>" (thanks Simon) - Fixed weird behaviour of "(e.g. at start of line" (thanks Tim) - Fixed handling of mail headers by adding "mail" option (thanks Struan) - Fixed bug in quoters (thanks Steve) - Added a C option to turn off special treatment of apparent lists (thanks Ingvar) 1.12 2003-05-27 DCONWAY - Now honours -- mail sig introducer (stops formatting that that point) - Now ignores mail headers - Added exportable &ignore_headers for when using in user-defined "ignore" subs - Now handles of embedded HTML entities (thanks David) - Added call to C for 5.6 compatibility (thanks Paolo) - Restricted normal numbering to the range 0-999 to prevent false numbering caused by a year (like 1999) at the start of a line (like this) - Fixed subtle bug with words starting with "ps-" being treated as post scripts (thanks Rashid!) 1.11 2003-05-07 DCONWAY - Enhanced "highlight" casing mode (thanks Tom) - Made hyphenation smarter (thanks Raj) 1.10 2003-04-09 DCONWAY - Fixed test.pl again!!! 1.08 2003-04-02 DCONWAY - Simplified test.pl 1.07 2003-04-02 DCONWAY - Tweaked pod to remove invalid markup - Fixed left justification of last line of fully justified text (thanks Elias) - Devolved &from and &tag to Text::Reform - Fixed incorrect handling of stringifiable objects (thanks dLux) - Fixed bugs on null input (now short-circuits) - Fixed unwarranted trimming of trailing newlines (thanks Mark) - Added C option to control renumbering - Preserved capitalization of abbreviations under case changes (thanks Alex) - Added "autocentre" flag to switch off auto-centring of paras - Added "ignore" flag to control which paragraphs are reformatted (thanks Tony) 1.04 2000-12-04 DCONWAY - Limited numerical bullets to 3 digits. This stops autoformat from misclassifying orphaned years such as 2001. - Added new abbreviations - Doc patch on numerical formatting (thanks Andy) - Major bug fixes to renumbering mechanism - Turned off renumbering in quoted text. - Added correct autostringification of autostringifying objects passed to &form. (Thanks Leon) - Cleaned up "evil" exporting code left over from testing (Thanks Rick) 1.03 2000-10-25 DCONWAY - Tweaked test.pl and POD - required 5.005 (module uses funky stuff that's broken in earlier perls - sorry Dave) - added break_TeX subroutine to take advantage of TeX::Hyphen if it's installed. - documented "sticky" config mode - Changed semantics of footer generation slightly (see doc) - fixed niggle in widow handling under full justification - Added pagenum option to control page numbering - Added three-part hash specification option for headers and footers (thanks Chaim) - Added separator handling to autoformat -- also fixes underlining of heading (thanks very much Simon) 1.02 2000-08-05 DCONWAY 0.01 1997-11-03 - original version; created by h2xs 1.18 Text-Autoformat-1.74/config.emacs000755 000765 000024 00000000566 12626343224 017241 0ustar00neilbstaff000000 000000 ;; Add these lines to your .emacs and you will be happy with ;; p5-Text-Autoformat. ;; Use ctrl-c k to reformat a region. ;; Set a global key for autoformat region (global-set-key (kbd "C-c k") (lambda () (interactive) (shell-command-on-region (region-beginning) (region-end) "perl -MText::Autoformat -e \"{autoformat{all=>1};}\"" (current-buffer) t))) Text-Autoformat-1.74/config.vim000755 000765 000024 00000001143 12626343224 016734 0ustar00neilbstaff000000 000000 " Add these lines to your .vimrc and you will be happy with " p5-Text-Autoformat. Use ctrl-k to reformat a paragraph and ctrl-n to " reformat all text from the cursor. imap !G perl -MText::Autoformat -e "{autoformat;}" nmap !G perl -MText::Autoformat -e "{autoformat;}" vmap !G perl -MText::Autoformat -e "{autoformat;}" imap !G perl -MText::Autoformat -e "{autoformat{all=>1};}" nmap !G perl -MText::Autoformat -e "{autoformat{all=>1};}" vmap !G perl -MText::Autoformat -e "{autoformat{all=>1};}" Text-Autoformat-1.74/dist.ini000644 000765 000024 00000000517 12626343224 016417 0ustar00neilbstaff000000 000000 name = Text-Autoformat author = Damian Conway license = Perl_5 copyright_holder = Damian Conway copyright_year = 1997 main_module = lib/Text/Autoformat.pm version = 1.74 [@Basic] [PkgVersion] [AutoPrereqs] [MetaJSON] [GithubMeta] [Git::Tag] tag_message= [Git::Push] Text-Autoformat-1.74/lib/000755 000765 000024 00000000000 12626343224 015516 5ustar00neilbstaff000000 000000 Text-Autoformat-1.74/LICENSE000644 000765 000024 00000043660 12626343224 015766 0ustar00neilbstaff000000 000000 This software is copyright (c) 1997 by Damian Conway. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 1997 by Damian Conway. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 1997 by Damian Conway. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Text-Autoformat-1.74/Makefile.PL000644 000765 000024 00000002541 12626343224 016724 0ustar00neilbstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.037. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Automatic text wrapping and reformatting", "AUTHOR" => "Damian Conway ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Text-Autoformat", "EXE_FILES" => [], "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "Text::Autoformat", "PREREQ_PM" => { "Carp" => 0, "Exporter" => 0, "Text::Reform" => 0, "Text::Tabs" => 0, "overload" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Test::More" => "0.88", "utf8" => 0 }, "VERSION" => "1.74", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "Test::More" => "0.88", "Text::Reform" => 0, "Text::Tabs" => 0, "overload" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Text-Autoformat-1.74/MANIFEST000644 000765 000024 00000000506 12626343224 016102 0ustar00neilbstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.037. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README config.emacs config.vim dist.ini lib/Text/Autoformat.pm lib/Text/Autoformat/Hang.pm lib/Text/Autoformat/NullHang.pm t/00.load.t t/01.ignore.t t/02.empty-string.t t/02.wide-numbers.t Text-Autoformat-1.74/META.json000644 000765 000024 00000002421 12626343224 016370 0ustar00neilbstaff000000 000000 { "abstract" : "Automatic text wrapping and reformatting", "author" : [ "Damian Conway " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Text-Autoformat", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "Text::Reform" : "0", "Text::Tabs" : "0", "overload" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.88", "utf8" : "0" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/neilb/Text-Autoformat", "repository" : { "type" : "git", "url" : "https://github.com/neilb/Text-Autoformat.git", "web" : "https://github.com/neilb/Text-Autoformat" } }, "version" : "1.74" } Text-Autoformat-1.74/META.yml000644 000765 000024 00000001301 12626343224 016214 0ustar00neilbstaff000000 000000 --- abstract: 'Automatic text wrapping and reformatting' author: - 'Damian Conway ' build_requires: Test::More: '0.88' utf8: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Text-Autoformat requires: Carp: '0' Exporter: '0' Text::Reform: '0' Text::Tabs: '0' overload: '0' perl: '5.006' strict: '0' warnings: '0' resources: homepage: https://github.com/neilb/Text-Autoformat repository: https://github.com/neilb/Text-Autoformat.git version: '1.74' Text-Autoformat-1.74/README000644 000765 000024 00000000574 12626343224 015636 0ustar00neilbstaff000000 000000 This archive contains the distribution Text-Autoformat, version 1.74: Automatic text wrapping and reformatting This software is copyright (c) 1997 by Damian Conway. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.037. Text-Autoformat-1.74/t/000755 000765 000024 00000000000 12626343224 015213 5ustar00neilbstaff000000 000000 Text-Autoformat-1.74/t/00.load.t000644 000765 000024 00000000204 12626343224 016531 0ustar00neilbstaff000000 000000 use Test::More tests => 1; BEGIN { use_ok( 'Text::Autoformat' ); } diag( "Testing Text::Autoformat $Text::Autoformat::VERSION" ); Text-Autoformat-1.74/t/01.ignore.t000644 000765 000024 00000004264 12626343224 017110 0ustar00neilbstaff000000 000000 use Test::More 'no_plan'; use Text::Autoformat; my $in = # 10 20 30 40 #234567890123456789012345678901234567890123457890 'This is a very simple test to see what will happen whenver we start using an ARRAY of ARGUMENTS to the ignore parameter inside Text::Autoformat. This is a very cool module that is going to save me from having to do a whole lot of work on my own! I sure do hope that this works. I am going to be very bummed if it does not.'; my $expected = 'This is a very simple test to see what will happen whenver we start using an ARRAY of ARGUMENTS to the ignore parameter inside Text::Autoformat. This is a very cool module that is going to save me from having to do a whole lot of work on my own! I sure do hope that this works. I am going to be very bummed if it does not.'; my $result = autoformat( $in, { right => 38, ignore => [ qr/ARRAY/, qr/bummed/ ] } ); chomp($result); is ( $result, $expected, 'Test formatting with multiple ignore parameters' ); $in = # 10 20 30 40 #234567890123456789012345678901234567890123457890 'From: "me" To: "you" Subject: Text::Autoformat rocks my world oh so much!!! Hey there, Have you tried Text::Autoformat yet? It is the coolest thing in this world! You really need to try it. Regards, Your friend with a very very very very very long name that should not wrap.'; $expected = 'From: "me" To: "you" Subject: Text::Autoformat rocks my world oh so much!!! Hey there, Have you tried Text::Autoformat yet? It is the coolest thing in this world! You really need to try it. Regards, Your friend with a very very very very very long name that should not wrap.'; $result = autoformat( $in, { right => 38, ignore => qr/^Regards,/, mail => 1 } ); chomp($result); is ( $result, $expected, 'Test formatting with ignore param and mail headers' ); Text-Autoformat-1.74/t/02.empty-string.t000644 000765 000024 00000000476 12626343224 020271 0ustar00neilbstaff000000 000000 #! perl use strict; use warnings; use Text::Autoformat qw/ autoformat /; use Test::More 0.88 tests => 1; my $input = ''; my $expected_output = ''; my $output = autoformat($input); ok(defined($output) && $output eq $expected_output, "Empty string input should result in empty string output"); Text-Autoformat-1.74/t/02.wide-numbers.t000644 000765 000024 00000000617 12626343224 020225 0ustar00neilbstaff000000 000000 use utf8; use strict; use Test::More tests => 1; use Text::Autoformat; my $str = <<'END'; 1. Analyze problem 2. Design algorithm 6. Code solution 4. Test 2. Ship END my $after = autoformat $str, { lists => 'number', all => 1, # rjbs thinks this should not be needed -- rjbs, 2015-04-24 }; unlike( $after, qr/2/, "we do not mangle lists numbered with non-ASCII numbers", ); Text-Autoformat-1.74/lib/Text/000755 000765 000024 00000000000 12626343224 016442 5ustar00neilbstaff000000 000000 Text-Autoformat-1.74/lib/Text/Autoformat/000755 000765 000024 00000000000 12626343224 020563 5ustar00neilbstaff000000 000000 Text-Autoformat-1.74/lib/Text/Autoformat.pm000644 000765 000024 00000131407 12626343224 021127 0ustar00neilbstaff000000 000000 package Text::Autoformat; $Text::Autoformat::VERSION = '1.74'; use 5.006; use strict; use warnings; use Carp; require Exporter; use Text::Reform qw( form tag break_at break_with break_wrap break_TeX ); use Text::Autoformat::Hang; use Text::Autoformat::NullHang; our @ISA = qw(Exporter); our @EXPORT = qw( autoformat ); our @EXPORT_OK = qw( form tag break_at break_with break_wrap break_TeX ignore_headers ); my %std_highlight_ignore = map {$_=>1} qw { a an at as and are but by ere for from in into is of on onto or over per the to that than until unto upon via with while whilst within without }; my $STD_HIGHLIGHT_IGNORES = sub { my ($word) = @_; return $std_highlight_ignore{lc $word} ? recase($word,'lower') : recase($word,'title'); }; my @entities = qw { Á á Â â Æ æ À à Α α à ã Ä ä Β β Ç ç Χ χ Δ δ É é Ê ê È è Ε ε Η η Ð ð Ë ë Γ γ Í í Î î Ì ì Ι ι Ï ï Κ κ Λ λ Μ μ Ñ ñ Ν ν Ó ó Ô ô Œ œ Ò ò Ω ω Ο ο Õ õ Ö ö Φ φ Π π ″ ′ Ψ ψ Ρ ρ Š š Σ σ Τ τ Θ θ Þ þ Ú ú Û û Ù ù Υ υ Ü ü Ξ ξ Ý ý Ÿ ÿ Ζ ζ }; my %lower_entities = @entities; my %upper_entities = reverse @entities; my %casing = ( lower => [ \%lower_entities, \%lower_entities, sub { $_ = lc }, sub { $_ = lc } ], upper => [ \%upper_entities, \%upper_entities, sub { $_ = uc }, sub { $_ = uc } ], title => [ \%upper_entities, \%lower_entities, sub { $_ = ucfirst lc }, sub { $_ = lc } ], ); my $default_margin = 72; my $default_widow = 10; $Text::Autoformat::widow_slack = 0.1; sub defn($) { return $_[0] if defined $_[0]; return ""; } my $ignore_headers = qr/ \A (?: From \b .* $)? (?: [^:\n]+ : .* \n (?: [ \t] .* \n)* )+ \s* \Z /mx; my $ignore_indent = qr/^[^\S\n].*(\n[^\S\n].*)*$/; sub ignore_headers { $_[0] && /$ignore_headers/ } # BITS OF A TEXT LINE my $quotechar = qq{[!#%=|:;]}; my $quotechunk = qq{(?:$quotechar(?![a-z])|(?:[a-z]\\w*)?>+)}; my $QUOTER = qq{(?:(?i)(?:$quotechunk(?:[ \\t]*$quotechunk)*))}; my $separator = q/(?:[-_]{2,}|[=#*]{3,}|[+~]{4,})/; use overload; sub autoformat # ($text, %args) { my ($text,%args,$toSTDOUT); foreach ( @_ ) { if (ref eq 'HASH') { %args = (%args, %$_) } elsif (!defined($text) && !ref || overload::Method($_,'""')) { $text = "$_" } else { croak q{Usage: autoformat([text],[{options}])} } } unless (defined $text) { $text = join("",); $toSTDOUT = !defined wantarray(); } return $text unless $text =~ /\S/; $args{right} = $default_margin unless exists $args{right}; $args{justify} = "" unless exists $args{justify}; $args{widow} = 0 if ($args{justify}||"") =~ /full/; $args{widow} = $default_widow unless exists $args{widow}; $args{case} = '' unless exists $args{case}; $args{lists} = 1 unless exists $args{lists}; $args{squeeze} = 1 unless exists $args{squeeze}; $args{gap} = 0 unless exists $args{gap}; $args{break} = break_at('-') unless exists $args{break}; $args{impfill} = ! exists $args{fill}; $args{expfill} = $args{fill}; $args{tabspace} = 8 unless exists $args{tabspace}; $args{renumber} = 1 unless exists $args{renumber}; $args{autocentre} = 1 unless exists $args{autocentre}; $args{_centred} = 1 if $args{justify} =~ /cent(er(ed)?|red?)/; $args{all} ||= $args{mail}; # SPECIAL IGNORANCE... if ($args{ignore}) { $args{all} = 1; $args{ignore} = _build_ignore( $args{ignore} ); } else { $args{ignore} = sub{0}; } if ( $args{mail} ) { my $ignore = $args{ignore}; $args{ignore} = sub { $ignore->(@_) || ignore_headers(@_) }; } # DETABIFY my @rawlines = split /\n/, $text; use Text::Tabs; $tabstop = $args{tabspace}; @rawlines = expand(@rawlines); # HANDLE QUOTING CHANGE my $quoter = exists $args{quoter} ? $args{quoter} : $QUOTER; $quoter =~ s//$QUOTER/g; # PARSE EACH LINE my $pre = 0; my @lines; foreach (@rawlines) { push @lines, { raw => $_ }; s/\A([ \t]*)($quoter?)([ \t]*)// or die "Internal Error ($@) on '$_'"; $lines[-1]{presig} = $lines[-1]{prespace} = defn $1; $lines[-1]{presig} .= $lines[-1]{quoter} = defn $2; $lines[-1]{presig} .= $lines[-1]{quotespace} = defn $3; $lines[-1]{hang} = Text::Autoformat::Hang->new($_, $args{lists}); s/([ \t]*)(.*?)(\s*)$// or die "Internal Error ($@) on '$_'"; $lines[-1]{hangspace} = defn $1; $lines[-1]{text} = defn $2; $lines[-1]{empty} = $lines[-1]{hang}->empty() && $2 !~ /\S/; $lines[-1]{separator} = $lines[-1]{text} =~ /^$separator$/; } # SUBDIVIDE DOCUMENT INTO COHERENT SUBSECTIONS my @chunks; push @chunks, [shift @lines]; foreach my $line (@lines) { if ($line->{separator} || $line->{quoter} ne $chunks[-1][-1]->{quoter} || $line->{empty} || @chunks && $chunks[-1][-1]->{empty}) { push @chunks, [$line]; } else { push @{$chunks[-1]}, $line; } } # DETECT CENTRED PARAS CHUNK: foreach my $chunk ( @chunks ) { next CHUNK if !$args{autocentre} || @$chunk < 2 || $chunk->[0]{hang}; my @length; my $ave = 0; foreach my $line (@$chunk) { my $prespace = $line->{quoter} ? $line->{quotespace} : $line->{prespace}; my $pagewidth = 2*length($prespace) + length($line->{text}); push @length, [length $prespace,$pagewidth]; $ave += $pagewidth; } $ave /= @length; my $diffpre = 0; foreach my $l (0..$#length) { next CHUNK unless abs($length[$l][1]-$ave) <= 2; $diffpre ||= $length[$l-1][0] != $length[$l][0] if $l > 0; } next CHUNK unless $diffpre; foreach my $line (@$chunk) { $line->{centred} = 1; ($line->{quoter} ? $line->{quotespace} : $line->{prespace}) = ""; } } # REDIVIDE INTO PARAGRAPHS my @paras; foreach my $chunk ( @chunks ) { my $first = 1; my $firstfrom; foreach my $line ( @{$chunk} ) { if ($first || $line->{quoter} ne $paras[-1]->{quoter} || $paras[-1]->{separator} || !$line->{hang}->empty ) { push @paras, $line; $first = 0; $firstfrom = length($line->{raw}) - length($line->{text}); } else { my $extraspace = length($line->{raw}) - length($line->{text}) - $firstfrom; $extraspace = 0 if $extraspace < 0; $paras[-1]->{text} .= "\n" . q{ }x$extraspace . $line->{text}; $paras[-1]->{raw} .= "\n" . $line->{raw}; } } } # SELECT PARAS TO HANDLE my $remainder = ""; if ($args{all}) { # STOP AT MAIL TERMINATOR IF $args{mail} my $lastignored = 1; for my $index (0..$#paras) { local $_ = $paras[$index]{raw} . "\n"; $paras[$index]{ignore} = $args{ignore}($lastignored); $lastignored &&= $paras[$index]{ignore}; next unless $args{mail} && /^--\s*$/; $remainder = join "\n", map { $_->{raw} } splice @paras, $index; $remainder .= "\n" unless $remainder =~ /\n\z/; last; } } else { # JUST THE FIRST PARA $remainder = join "\n", map { $_->{raw} } @paras[1..$#paras]; $remainder .= "\n" unless $remainder =~ /\n\z/; @paras = ( $paras[0] ); } # RE-CASE TEXT if ($args{case}) { foreach my $para ( @paras ) { next if $para->{ignore}; if (ref $args{case} eq 'CODE') { $para->{text} = entitle($para->{text}, $args{case}); } elsif ($args{case} =~ /upper/i) { $para->{text} = recase($para->{text}, 'upper'); } elsif ($args{case} =~ /lower/i) { $para->{text} = recase($para->{text}, 'lower'); } elsif ($args{case} =~ /title/i) { $para->{text} = entitle($para->{text}, 0); } elsif ($args{case} =~ /highlight/i) { $para->{text} = entitle($para->{text}, $STD_HIGHLIGHT_IGNORES); } elsif ($args{case} =~ /sentence(\s*)/i) { my $trailer = $1; $args{squeeze}=0 if $trailer && $trailer ne " "; ensentence(); $para->{text} =~ s/(\S+(\s+|$))/ensentence($1, $trailer)/ge; } $para->{text} =~ s/\b([A-Z])[.]/\U$1./gi; # ABBREVS } } # ALIGN QUOTERS # DETERMINE HANGING MARKER TYPE (BULLET, ALPHA, ROMAN, ETC.) my %sigs; my $lastquoted = 0; my $lastprespace = 0; for my $i ( 0..$#paras ) { my $para = $paras[$i]; next if $para->{ignore}; if ($para->{quoter}) { if ($lastquoted) { $para->{prespace} = $lastprespace } else { $lastquoted = 1; $lastprespace = $para->{prespace} } } else { $lastquoted = 0; } } # RENUMBER PARAGRAPHS for my $para ( @paras ) { next if $para->{ignore}; my $sig = $para->{presig} . $para->{hang}->signature(); push @{$sigs{$sig}{hangref}}, $para; $sigs{$sig}{hangfields} = $para->{hang}->fields()-1 unless defined $sigs{$sig}{hangfields}; } while (my ($sig,$val) = each %sigs) { next unless $sig =~ /rom/; field: for my $field ( 0..$val->{hangfields} ) { my $romlen = 0; foreach my $para ( @{$val->{hangref}} ) { my $hang = $para->{hang}; my $fieldtype = $hang->field($field); next field unless $fieldtype && $fieldtype =~ /rom|let/; if ($fieldtype eq 'let') { foreach my $para ( @{$val->{hangref}} ) { $hang->field($field=>'let') } } else { $romlen += length $hang->val($field); } } # NO ROMAN LETTER > 1 CHAR -> ALPHABETICS if ($romlen <= @{$val->{hangref}}) { foreach my $para ( @{$val->{hangref}} ) { $para->{hang}->field($field=>'let') } } } } my %prev; for my $para ( @paras ) { next if $para->{ignore}; my $sig = $para->{presig} . $para->{hang}->signature(); if ($args{renumber}) { unless ($para->{quoter}) { $para->{hang}->incr($prev{""}, $prev{$sig}); $prev{""} = $prev{$sig} = $para->{hang} unless $para->{hang}->empty; } } # COLLECT MAXIMAL HANG LENGTHS BY SIGNATURE my $siglen = $para->{hang}->length(); $sigs{$sig}{hanglen} = $siglen if ! $sigs{$sig}{hanglen} || $sigs{$sig}{hanglen} < $siglen; } # PROPAGATE MAXIMAL HANG LENGTH while (my ($sig,$val) = each %sigs) { foreach (@{$val->{hangref}}) { $_->{hanglen} = $val->{hanglen}; } } # BUILD FORMAT FOR EACH PARA THEN FILL IT $text = ""; my $gap = @paras && $paras[0]->{empty} ? 0 : $args{gap}; for my $para ( @paras ) { if ($para->{empty}) { $gap += 1 + ($para->{text} =~ tr/\n/\n/); } if ($para->{ignore}) { $text .= (!$para->{empty} ? "\n"x($args{gap}-$gap > 0 ? ($args{gap}-$gap) : 0) : "") ; $text .= $para->{raw}; $text .= "\n" unless $para->{raw} =~ /\n\z/; } else { my $leftmargin = $args{left} ? " "x($args{left}-1) : $para->{prespace}; my $hlen = $para->{hanglen} || $para->{hang}->length; my $hfield = ($hlen==1 ? '~' : '>'x$hlen); my @hang; push @hang, $para->{hang}->stringify if $hlen; my $format = $leftmargin . quotemeta($para->{quoter}) . $para->{quotespace} . $hfield . $para->{hangspace}; my $rightslack = int (($args{right}-length $leftmargin)*$Text::Autoformat::widow_slack); my ($widow_okay, $rightindent, $firsttext, $newtext) = (0,0); do { my $tlen = $args{right}-$rightindent-length($leftmargin . $para->{quoter} . $para->{quotespace} . $hfield . $para->{hangspace}); next if blockquote($text,$para, $format, $tlen, \@hang, \%args); my $tfield = ( $tlen==1 ? '~' : $para->{centred}||$args{_centred} ? '|'x$tlen : $args{justify} eq 'right' ? ']'x$tlen : $args{justify} eq 'full' ? '['x($tlen-2) . ']]' : $para->{centred}||$args{_centred} ? '|'x$tlen : '['x$tlen ); my $tryformat = "$format$tfield"; $newtext = (!$para->{empty} ? "\n"x($args{gap} > $gap ? ($args{gap}-$gap) : 0) : "") . form( { squeeze=>$args{squeeze}, trim=>1, break=>$args{break}, fill => !(!($args{expfill} || $args{impfill} && !$para->{centred})) }, $tryformat, @hang, $para->{text}); $firsttext ||= $newtext; (my $widow) = $newtext =~ /([^\n]*)$/; $widow =~ s/^\s+//; $widow_okay = $para->{empty} || length($widow) >= $args{widow}; } until $widow_okay || ++$rightindent > $rightslack; $text .= $widow_okay ? $newtext : $firsttext; } $gap = 0 unless $para->{empty}; } # RETURN FORMATTED TEXT if ($toSTDOUT) { print STDOUT $text . $remainder; return } return $text . $remainder; } sub _build_ignore { my $ignore_arg = shift; my $ig_type = ref $ignore_arg; my $ignore; if ($ig_type eq 'Regexp') { my $regex = $ignore_arg; $ignore = sub { /$regex/ }; } elsif ($ig_type eq 'ARRAY') { my @elements = map { _build_ignore($_) } @$ignore_arg; $ignore = sub { for my $sub (@elements) { return 1 if $sub->(@_) } return 0; }; } elsif ($ignore_arg =~ /^indent/i) { $ignore = sub { ignore_headers(@_) || /$ignore_indent/ }; } else { $ignore = $ignore_arg; } croak "Expected suboutine reference as value for -ignore option" if ref $ignore ne 'CODE'; return $ignore; } my $alpha = qr/[^\W\d_]/; my $notalpha = qr/[\W\d_]/; my $word = qr/\pL(?:\pL'?)*/; my $upper = qr/[^\Wa-z\d_]/; my $lower = qr/[^\WA-Z\d_]/; my $mixed = qr/$alpha*?(?:$lower$upper|$upper$lower)$alpha*/; sub recase { my ($origtext, $case) = @_; my ($entities, $other_entities, $first, $rest) = @{$casing{$case}}; my $text = ""; my @pieces = split /(&[a-z]+;)/i, $origtext; push @pieces, "" if @pieces % 2; return $text unless @pieces; local $_ = shift @pieces; if (length $_) { $entities = $other_entities; &$first; $text .= $_; } return $text unless @pieces; $_ = shift @pieces; $text .= $entities->{$_} || $_; while (@pieces) { $_ = shift @pieces; &$rest; $text .= $_; $_ = shift @pieces; $text .= $other_entities->{$_} || $_; } return $text; } my $alword = qr{(?:\pL|&[a-z]+;)(?:[\pL']|&[a-z]+;)*}i; sub entitle { my ($text, $retitler_ref) = @_; # put into lowercase if on stop list, else titlecase $text =~ s{($alword)} { $retitler_ref ? $retitler_ref->($1) : recase($1,'title') }gex; if ($retitler_ref == $STD_HIGHLIGHT_IGNORES) { # First and final words always capitalized... $text =~ s/^($alword) /recase($1,'title')/ex; $text =~ s/ ($alword)$/recase($1,'title')/ex; # treat parethesized portion as a complete title $text =~ s/\( ($alword) /'('.recase($1,'title')/ex; $text =~ s/($alword) \) /recase($1,'title').')'/ex; # capitalize first word following colon or semi-colon $text =~ s/ ( [:;] \s+ ) ($alword) /$1 . recase($2,'title')/ex; } return $text; } my $gen_abbrev = join '|', qw{ etc[.] pp[.] ph[.]?d[.] }, '(?:[A-Z][.])(?:[A-Z][.])+', '(^[^a-zA-Z]*([a-z][.])+)'; my $term = q{(?:[.]|[!?]+)}; my $eos = 1; my $brsent = 0; sub ensentence { do { $eos = 1; return } unless @_; my ($str, $trailer) = @_; if ($str =~ /^([^a-z]*)I[^a-z]*?($term?)[^a-z]*$/i) { $eos = $2; $brsent = $1 =~ /^[[(]/; return uc $str } unless ($str =~ /[a-z].*[A-Z]|[A-Z].*[a-z]/) { $str = lc $str; } if ($eos) { $str =~ s/([a-z])/uc $1/ie; $brsent = $str =~ /^[[(]/; } $eos = $str !~ /^($gen_abbrev)[^a-z]*\s/i && $str =~ /[a-z][^a-z]*$term([^a-z]*)\s/ && !($1=~/[])]/ && !$brsent); $str =~ s/\s+$/$trailer/ if $eos && $trailer; return $str; } # blockquote($text,$para, $format, $tlen, \@hang, \%args); sub blockquote { my ($dummy, $para, $format, $tlen, $hang, $args) = @_; $para->{text} =~ / \A(\s*) # $1 - leading whitespace (quotation) (["']|``) # $2 - opening quotemark (.*) # $3 - quotation (''|\2) # $4 closing quotemark \s*?\n # trailing whitespace (\1[ ]+) # $5 - leading whitespace (attribution) (--|-) # $6 - attribution introducer (.*?$) # $7 - attribution line 1 ((\5.*?$)*) # $8 - attributions lines 2-N \s*\Z /xsm or return; #print "[$1][$2][$3][$4][$5][$6][$7]\n"; my $indent = length $1; my $text = $2.$3.$4; my $qindent = length $2; my $aindent = length $5; my $attribintro = $6; my $attrib = $7.$8; $text =~ s/\n/ /g; $_[0] .= form {squeeze=>$args->{squeeze}, trim=>1, fill => $args->{expfill} }, $format . q{ }x$indent . q{<}x$tlen, @$hang, $text, $format . q{ }x($qindent) . q{[}x($tlen-$qindent), @$hang, $text, {squeeze=>0}, $format . q{ } x $aindent . q{>> } . q{[}x($tlen-$aindent-3), @$hang, $attribintro, $attrib; return 1; } 1; __END__ =head1 NAME Text::Autoformat - Automatic text wrapping and reformatting =head1 VERSION This document describes version 1.72 of Text::Autoformat =head1 SYNOPSIS # Minimal use: read from STDIN, format to STDOUT... use Text::Autoformat; autoformat; # In-memory formatting... $formatted = autoformat $rawtext; # Configuration... $formatted = autoformat $rawtext, { %options }; # Margins (1..72 by default)... $formatted = autoformat $rawtext, { left=>8, right=>70 }; # Justification (left by default)... $formatted = autoformat $rawtext, { justify => 'left' }; $formatted = autoformat $rawtext, { justify => 'right' }; $formatted = autoformat $rawtext, { justify => 'full' }; $formatted = autoformat $rawtext, { justify => 'centre' }; # Filling (does so by default)... $formatted = autoformat $rawtext, { fill=>0 }; # Squeezing whitespace (does so by default)... $formatted = autoformat $rawtext, { squeeze=>0 }; # Select appropriate tabspacing (default is 8 spaces per tab): $formatted = autoformat $rawtext, { tabspace=>4 }; # Case conversions... $formatted = autoformat $rawtext, { case => 'lower' }; $formatted = autoformat $rawtext, { case => 'upper' }; $formatted = autoformat $rawtext, { case => 'sentence' }; $formatted = autoformat $rawtext, { case => 'title' }; $formatted = autoformat $rawtext, { case => 'highlight' }; $formatted = autoformat $rawtext, { case => \&my_case_func }; # Selective reformatting $formatted = autoformat $rawtext, { ignore=>qr/^\t/ }; =head1 BACKGROUND =head2 The problem Perl plaintext formatters just aren't smart enough. Given a typical piece of plaintext in need of formatting: In comp.lang.perl.misc you wrote: : > writes: : > CN> PERL sux because: : > CN> * It doesn't have a switch statement and you have to put $ : > CN>signs in front of everything : > CN> * There are too many OR operators: having |, || and 'or' : > CN>operators is confusing : > CN> * VB rools, yeah!!!!!!!!! : > CN> So anyway, how can I stop reloads on a web page? : > CN> Email replies only, thanks - I don't read this newsgroup. : > : > Begone, sirrah! You are a pathetic, Bill-loving, microcephalic : > script-infant. : Sheesh, what's with this group - ask a question, get toasted! And how : *dare* you accuse me of Ianuphilia! both the venerable Unix L tool and Perl's standard Text::Wrap module produce: In comp.lang.perl.misc you wrote: : > writes: : > CN> PERL sux because: : > CN> * It doesn't have a switch statement and you have to put $ : > CN>signs in front of everything : > CN> * There are too many OR operators: having |, || and 'or' : > CN>operators is confusing : > CN> * VB rools, yeah!!!!!!!!! : > CN> So anyway, how can I stop reloads on a web page? : > CN> Email replies only, thanks - I don't read this newsgroup. : > : > Begone, sirrah! You are a pathetic, Bill-loving, microcephalic : > script-infant. : Sheesh, what's with this group - ask a question, get toasted! And how : *dare* you accuse me of Ianuphilia! Other formatting modules -- such as Text::Correct and Text::Format -- provide more control over their output, but produce equally poor results when applied to arbitrary input. They simply don't understand the structural conventions of the text they're reformatting. =head2 The solution The Text::Autoformat module provides a subroutine named C that wraps text to specified margins. However, C reformats its input by analysing the text's structure, so it wraps the above example like so: In comp.lang.perl.misc you wrote: : > writes: : > CN> PERL sux because: : > CN> * It doesn't have a switch statement and you : > CN> have to put $ signs in front of everything : > CN> * There are too many OR operators: having |, || : > CN> and 'or' operators is confusing : > CN> * VB rools, yeah!!!!!!!!! So anyway, how can I : > CN> stop reloads on a web page? Email replies : > CN> only, thanks - I don't read this newsgroup. : > : > Begone, sirrah! You are a pathetic, Bill-loving, : > microcephalic script-infant. : Sheesh, what's with this group - ask a question, get toasted! : And how *dare* you accuse me of Ianuphilia! Note that the various quoting conventions have been observed. In fact, their structure has been used to determine where some paragraphs begin. Furthermore C correctly distinguished between the leading '*' bullets of the nested list (which were outdented) and the leading emphatic '*' of "*dare*" (which was inlined). =head1 DESCRIPTION =head2 Paragraphs The fundamental task of the C subroutine is to identify and rearrange independent paragraphs in a text. Paragraphs typically consist of a series of lines containing at least one non-whitespace character, followed by one or more lines containing only optional whitespace. This is a more liberal definition than many other formatters use: most require an empty line to terminate a paragraph. Paragraphs may also be denoted by bulleting, numbering, or quoting (see the following sections). Once a paragraph has been isolated, C fills and re-wraps its lines according to the margins that are specified in its argument list. These are placed after the text to be formatted, in a hash reference: $tidied = autoformat($messy, {left=>20, right=>60}); By default, C uses a left margin of 1 (first column) and a right margin of 72. You can also control whether (and how) C breaks words at the end of a line, using the C<'break'> option: # Turn off all hyphenation use Text::Autoformat qw(autoformat break_wrap); $tidied = autoformat($messy, {break=>break_wrap}); # Default hyphenation use Text::Autoformat qw(autoformat break_at); $tidied = autoformat($messy, {break=>break_at('-')}); # Use TeX::Hyphen module's hyphenation (module must be installed) use Text::Autoformat qw(autoformat break_TeX); $tidied = autoformat($messy, {break=>break_TeX}); Normally, C only reformats the first paragraph it encounters, and leaves the remainder of the text unaltered. This behaviour is useful because it allows a one-liner invoking the subroutine to be mapped onto a convenient keystroke in a text editor, to provide one-paragraph-at-a-time reformatting: % cat .exrc map f !Gperl -MText::Autoformat -e'autoformat' (Note that to facilitate such one-liners, if C is called in a void context without any text data, it takes its text from C and writes its result to C). To enable C to rearrange the entire input text at once, the C argument is used: $tidied_all = autoformat($messy, {left=>20, right=>60, all=>1}); C can also be directed to selectively reformat paragraphs, using the C argument: $tidied_some = autoformat($messy, {ignore=>qr/^[ \t]/}); The value for C may be a C'd regex, a subroutine reference, or the special string C<'indented'>. If a regex is specified, any paragraph whose original text matches that regex will not be reformatted (i.e. it will be printed verbatim). If a subroutine is specified, that subroutine will be called once for each paragraph (with C<$_> set to the paragraph's text). The subroutine is expected to return a true or false value. If it returns true, the paragraph will not be reformatted. If the value of the C option is the string C<'indented'>, C will ignore any paragraph in which I line begins with a whitespace. You may also specify multiple C options by including them in an array-ref: $tidied_mesg = autoformat($messy, {ignore=>[qr/1/,'indented']}); One other special case of ignorance is ignoring mail headers and signature. This option is specified using the C argument: $tidied_mesg = autoformat($messy_mesg, {mail=>1}); Note that the C or C options automatically imply C. =head2 Bulleting and (re-)numbering Often plaintext will include lists that are either: * bulleted, * simply numbered (i.e. 1., 2., 3., etc.), or * hierarchically numbered (1, 1.1, 1.2, 1.3, 2, 2.1. and so forth). In such lists, each bulleted item is implicitly a separate paragraph, and is formatted individually, with the appropriate indentation: * bulleted, * simply numbered (i.e. 1., 2., 3., etc.), or * hierarchically numbered (1, 1.1, 1.2, 1.3, 2, 2.1. and so forth). More importantly, if the points are numbered, the numbering is checked and reordered. For example, a list whose points have been rearranged: 1. Analyze problem 3. Design algorithm 1. Code solution 5. Test 4. Ship would be renumbered automatically by C: 1. Analyze problem 2. Design algorithm 3. Code solution 4. Test 5. Ship The same reordering would be performed if the "numbering" was by letters (C C C etc.) or Roman numerals (C C C or by some combination of these (C<1a.> C<1b.> C<2a.> C<2b.> etc.) Handling disordered lists of letters and Roman numerals presents an interesting challenge. A list such as: A. Put cat in box. D. Close lid. E. Activate Geiger counter. should be reordered as C C C whereas: I. Put cat in box. D. Close lid. XLI. Activate Geiger counter. should be reordered C C C The C subroutine solves this problem by always interpreting alphabetic bullets as being letters, unless the full list consists only of valid Roman numerals, at least one of which is two or more characters long. Note that renumbering starts at the first number actually given, rather than restarting at the first possible number. To renumber from 1 (or A.) you must change the first numbered bullet to that. If automatic renumbering isn't wanted, just specify the C<'renumber'> option with a false value. Note that normal numbers above 1000 at the start of a line are no longer considered to be paragraph numbering. Numbered paragraphs running that high are exceptionally rare, and much rarer than paragraphs that look like these: Although it has long been popular (especially in the year 2001) to point out that we now live in the Future, many of the promised miracles of Future Life have failed to eventuate. This is a new phenomenon (it didn't happen in 1001) because the idea that the future might be different is a new phenomenon. which the former numbering rules caused to be formatted like this: Although it has long been popular (especially in the year 2001) to point out that we now live in the Future, many of the promised miracles of Future Life have failed to eventuate. This is a new phenomenon (it didn't happen in 2002) because the idea that the future might be different is a new phenomenon. but which are now formatted: Although it has long been popular (especially in the year 2001) to point out that we now live in the Future, many of the promised miracles of Future Life have failed to eventuate. This is a new phenomenon (it didn't happen in 1001) because the idea that the future might be different is a new phenomenon. If you want numbers less than 1000 (or other characters strings currently treated as bullets) to be ignored in this way, you can turn of list formatting entirely by setting the C<'lists'> option to a false value. You can also select which kinds of lists are recognized, by using a string as the value of lists: # Don't recognize Roman numerals or alphabetics as list markers... autoformat { lists => 'number, bullet' }, $text; # Don't recognize bullets or numbers as list markers... autoformat { lists => 'roman, alpha' }, $text; # Recognize everything except Roman numerals as list markers... autoformat { lists => 'number, bullet, alpha' }, $text; The string should contain one or more of the following words: C, C, C, C. C will ignore any list type that doesn't appear in the C<'lists'> string. =head2 Quoting Another case in which contiguous lines may be interpreted as belonging to different paragraphs, is where they are quoted with distinct quoters. For example: : > CN> So anyway, how can I stop reloads on a web page? Email : > CN> replies only, thanks - I don't read this newsgroup. : > Begone, sirrah! You are a pathetic, Bill-loving, : > microcephalic script-infant. : Sheesh, what's with this group - ask a question, get toasted! : And how *dare* you accuse me of Ianuphilia! C recognizes the various quoting conventions used in this example and treats it as three paragraphs to be independently reformatted. You may also override the default set of recognized quoters by specifying a C<'quoter'> argument when calling C. For example, to format lines such as: // This is a comment // in the standard C(++) // comment-to-EOL // format specify: autoformat($text, { quoter =E qr{//} }) Instead of completely replacing the existing set of quoters, you can I them by specifying a pattern that includes the metasequence C<< >>, which is then replaced by the module's standard pattern for quoters. So, for example, to add C to the set of existing quoters: autoformat($text, { quoter =E qr{//|} }) Block quotations present a different challenge. A typical formatter would render the following quotation: "We are all of us in the gutter, but some of us are looking at the stars" -- Oscar Wilde like so: "We are all of us in the gutter, but some of us are looking at the stars" -- Oscar Wilde C recognizes the quotation structure by matching the following regular expression against the text component of each paragraph: / \A(\s*) # leading whitespace for quotation (["']|``) # opening quotemark (.*) # quotation (''|\2) # closing quotemark \s*?\n # trailing whitespace after quotation (\1[ ]+) # leading whitespace for attribution # (must be indented more than # quotation) (--|-) # attribution introducer ([^\n]*?\n) # first attribution line ((\5[^\n]*?$)*) # other attribution lines # (indented no less than first line) \s*\Z # optional whitespace to end of paragraph /xsm When reformatted (see below), the indentation and the attribution structure will be preserved: "We are all of us in the gutter, but some of us are looking at the stars" -- Oscar Wilde =head2 Widow control Note that in the last example, C broke the line at column 68, four characters earlier than it should have. It did so because, if the full margin width had been used, the formatting would have left the last two words by themselves on an oddly short last line: "We are all of us in the gutter, but some of us are looking at the stars" This phenomenon is known as "widowing" and is heavily frowned upon in typesetting circles. It looks ugly in plaintext too, so C avoids it by stealing extra words from earlier lines in a paragraph, so as to leave enough for a reasonable last line. The heuristic used is that final lines must be at least 10 characters long (though this number may be adjusted by passing a C I> argument to C). If the last line is too short, the paragraph's right margin is reduced by one column, and the paragraph is reformatted. This process iterates until either the last line exceeds nine characters or the margins have been narrowed by 10% of their original separation. In the latter case, the reformatter gives up and uses its original formatting. =head2 Justification The C subroutine also takes a named argument: C<{justify =E I}>, which specifies how each paragraph is to be justified. The options are: C<'left'> (the default), C<'right',> C<'centre'> (or C<'center'>), and C<'full'>. These act on the complete paragraph text (but I on any quoters before that text). For example, with C<'right'> justification: R3> Now is the Winter of our discontent made R3> glorious Summer by this son of York. And all R3> the clouds that lour'd upon our house In the R3> deep bosom of the ocean buried. Full justification is interesting in a fixed-width medium like plaintext because it usually results in uneven spacing between words. Typically, formatters provide this by distributing the extra spaces into the first available gaps of each line: R3> Now is the Winter of our discontent made R3> glorious Summer by this son of York. And all R3> the clouds that lour'd upon our house In R3> the deep bosom of the ocean buried. This produces a rather jarring visual effect, so C reverses the strategy and inserts extra spaces at the end of lines: R3> Now is the Winter of our discontent made R3> glorious Summer by this son of York. And all R3> the clouds that lour'd upon our house In R3> the deep bosom of the ocean buried. Most readers find this less disconcerting. =head2 Implicit centring Even if explicit centring is not specified, C will attempt to automatically detect centred paragraphs and preserve their justification. It does this by examining each line of the paragraph and asking: "if this line were part of a centred paragraph, where would the centre line have been?" The answer can be determined by adding the length of leading whitespace before the first word, plus half the length of the full set of words on the line. That is, for a single line: $line =~ /^(\s*)(.*?)(\s*)$/ $centre = length($1)+0.5*length($2); By making the same estimate for every line, and then comparing the estimates, it is possible to deduce whether all the lines are centred with respect to the same axis of symmetry (with an allowance of E1 to cater for the inevitable rounding when the centre positions of even-length rows were originally computed). If a common axis of symmetry is detected, C assumes that the lines are supposed to be centred, and switches to centre-justification mode for that paragraph. Note that this behaviour can to switched off entirely by setting the C<"autocentre"> argument false. =head2 Case transformations The C subroutine can also optionally perform case conversions on the text it processes. The C<{case =E I}> argument allows the user to specify six different conversions: =over 4 =item C<'upper'> This mode unconditionally converts every letter in the reformatted text to upper-case; =item C<'lower'> This mode unconditionally converts every letter in the reformatted text to lower-case; =item C<'sentence'> This mode attempts to generate correctly-cased sentences from the input text. That is, the first letter after a sentence-terminating punctuator is converted to upper-case. Then, each subsequent word in the sentence is converted to lower-case, unless that word is originally mixed-case or contains punctuation. For example, under C<{case =E 'sentence'}>: 'POVERTY, MISERY, ETC. are the lot of the PhD candidate. alas!' becomes: 'Poverty, misery, etc. are the lot of the PhD candidate. Alas!' Note that C is clever enough to recognize that the period after abbreviations such as C is not a sentence terminator. If the argument is specified as C<'sentence '> (with one or more trailing whitespace characters) those characters are used to replace the single space that appears at the end of the sentence. For example, C'sentence '}>) would produce: 'Poverty, misery, etc. are the lot of the PhD candidate. Alas!' =item C<'title'> This mode behaves like C<'sentence'> except that the first letter of I word is capitalized: 'What I Did On My Summer Vacation In Monterey' =item C<'highlight'> This mode behaves like C<'title'> except that trivial words are not capitalized: 'What I Did on my Summer Vacation in Monterey' =item C If the argument for C<'case'> is a subroutine reference, that subroutine is applied to each word and the result replaces the word in the text. For example, to convert a string to hostage-case: my $ransom_note = sub { return join "", # ^ Reconcatenate map {/[aeiou]/i ? lc : uc} # | uPPeR aND LoWeR each split //, # | Break into chars shift; # | Take argument }; $text = autoformat($text, {case => $ransom_note }); # "FoR eXaMPLe, To CoNVeRT a STRiNG To HoSTaGe-CaSe:" Or to highlight particular words: my @SPECIAL = qw( perl camel wall ); sub highlight_specials { my ($word) = @_; return $word ~~ @SPECIAL ? uc($word) : $word; } $text = autoformat($text, {case => \&highlight_specials}); # "It is easier for a CAMEL to pass through a WALL of PERL..." =back =head2 Selective reformatting You can select which paragraphs C actually reformats (or, rather, those it I reformat) using the C<"ignore"> flag. For example: # Reformat all paras except those containing "verbatim"... print autoformat { all => 1, ignore => qr/verbatim/i }, $text; # Reformat all paras except those less that 3 lines long... print autoformat { all => 1, ignore => sub { tr/\n/\n/ < 3 } }, $text; # Reformat all paras except those that are indented... print autoformat { all => 1, ignore => qr/^\s/m }, $text; # Reformat all paras except those that are indented (easier)... print autoformat { all => 1, ignore => 'indented' }, $text; =head2 Handling tabs Text::Autoformat replaces any tabs in the text it's formatting with the appropriate number of spaces (using Text::Tabs to do its dirty work). It normally assumes that each tab is equivalent to 8 space characters, but you can change that default using the 'tabspace' option: print autoformat { tabspace => 4 }, $text; =head1 SEE ALSO L - provides functions for manual text wrapping and reformatting. L - provides a single function for justifying strings according to various styles. L - a class that provides methods for formatting text in various ways. L - format various Perl data structures as text, in different ways according to the type of data. =head1 REPOSITORY L =head1 AUTHOR Damian Conway (damian@conway.org) =head1 BUGS There are undoubtedly serious bugs lurking somewhere in code this funky :-) Bug reports and other feedback are most welcome. =head1 LICENCE AND COPYRIGHT Copyright (c) 1997-2007, Damian Conway C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Text-Autoformat-1.74/lib/Text/Autoformat/Hang.pm000644 000765 000024 00000014523 12626343224 022003 0ustar00neilbstaff000000 000000 package Text::Autoformat::Hang; $Text::Autoformat::Hang::VERSION = '1.74'; use 5.006; use strict; use warnings; # ROMAN NUMERALS sub inv($@) { my ($k, %inv)=shift; for(0..$#_) {$inv{$_[$_]}=$_*$k} %inv } my @unit= ( "" , qw ( I II III IV V VI VII VIII IX )); my @ten = ( "" , qw ( X XX XXX XL L LX LXX LXXX XC )); my @hund= ( "" , qw ( C CC CCC CD D DC DCC DCCC CM )); my @thou= ( "" , qw ( M MM MMM )); my %rval= (inv(1,@unit),inv(10,@ten),inv(100,@hund),inv(1000,@thou)); my $rbpat= join ")(",join("|",reverse @thou), join("|",reverse @hund), join("|",reverse @ten), join("|",reverse @unit); my $rpat= join ")(?:",join("|",reverse @thou), join("|",reverse @hund), join("|",reverse @ten), join("|",reverse @unit); my $rom = qq/(?:(?=[MDCLXVI])(?:$rpat))/; my $abbrev = join '|', qw{ etc[.] pp[.] ph[.]?d[.] }, "(?!$rom)(?:[A-Z][A-Za-z]+[.])+", '(?:[A-Z][.])(?:[A-Z][.])+'; sub fromRoman($) { return 0 unless $_[0] =~ /^.*?($rbpat).*$/i; return $rval{uc $1} + $rval{uc $2} + $rval{uc $3} + $rval{uc $4}; } sub toRoman($$) { my ($num,$example) = @_; return '' unless $num =~ /^([0-3]??)(\d??)(\d??)(\d)$/; my $roman = $thou[$1||0] . $hund[$2||0] . $ten[$3||0] . $unit[$4||0]; return $example=~/[A-Z]/ ? uc $roman : lc $roman; } # BITS OF A NUMERIC VALUE my $num = q/(?:[0-9]{1,3}\b(?!:[0-9][0-9]\b))/; # Ignore 8:20 etc. my $let = q/[A-Za-z]/; my $pbr = q/[[(<]/; my $sbr = q/])>/; my $ows = q/[ \t]*/; my %close = ( '[' => ']', '(' => ')', '<' => '>', "" => '' ); my $hangPS = qq{(?i:ps:|(?:p\\.?)+s\\b\\.?(?:[ \\t]*:)?)}; my $hangNB = qq{(?i:n\\.?b\\.?(?:[ \\t]*:)?)}; my $hangword = qq{(?:(?:Note)[ \\t]*:)}; my $hangbullet = qq{[*.+-]}; my $hang = qq{(?:(?i)(?:$hangNB|$hangword|$hangbullet)(?=[ \t]))}; # IMPLEMENTATION sub new { my ($class, $orig, $lists_mode) = @_; return Text::Autoformat::NullHang->new() if !$lists_mode; my $origlen = length $orig; my @vals; if ($_[1] =~ s#\A($hangPS)##) { @vals = { type => 'ps', val => $1 } } elsif ($lists_mode =~ /1|bullet/i && $_[1] =~ s#\A($hang)##) { @vals = { type => 'bul', val => $1 } } elsif ($_[1] =~ m#\A\([^\s)]+\s#) { @vals = (); } else { no warnings "all"; my $cut; while (length $_[1]) { last if $_[1] =~ m#\A($ows)($abbrev)# && (length $1 || !@vals); # ws-separated or first last if $_[1] =~ m{\A $ows $pbr [^$sbr \t]* \s}xms; $cut = $origlen - length $_[1]; my $pre = $_[1] =~ s#\A($ows$pbr$ows)## ? $1 : ""; my $val = ($lists_mode =~ /1|number/i && $_[1] =~ s#\A($num)##) ? { type=>'num', val=>$1 } : ($lists_mode =~ /1|roman/i && $_[1] =~ s#\A($rom)\b##i) ? { type=>'rom', val=>$1, nval=>fromRoman($1) } : ($lists_mode =~ /1|alpha/i && $_[1] =~ s#\A($let(?!$let))##i) ? { type=>'let', val=>$1 } : { val => "", type => "" }; $_[1] = $pre.$_[1] and last unless $val->{val}; $val->{post} = $pre && $_[1] =~ s#\A($ows()[.:/]?[$close{$pre}][.:/]?)## && $1 || $_[1] =~ s#\A($ows()[$sbr.:/])## && $1 || ""; $val->{pre} = $pre; $val->{cut} = $cut; push @vals, $val; } while (@vals && !$vals[-1]{post}) { $_[1] = substr($orig,pop(@vals)->{cut}); } } # check for orphaned years or unlikely Roman numerals... if (@vals==1 && defined $vals[0]->{post} && $vals[0]->{post} =~ /[\.>)]/) { my $v = $vals[0]; if ($v->{type} eq 'num' && $v->{val} >= 1000) { $_[1] = substr($orig,pop(@vals)->{cut}); } } return Text::Autoformat::NullHang->new if !@vals; bless \@vals, $class; } sub incr { no warnings "all"; my ($self, $prev, $prevsig) = @_; my $level; # check compatibility return unless $prev && !$prev->empty; for $level (0..(@$self<@$prev ? $#$self : $#$prev)) { if ($self->[$level]{type} ne $prev->[$level]{type}) { return if @$self<=@$prev; # no incr if going up $prev = $prevsig; last; } } return unless $prev && !$prev->empty; if ($self->[0]{type} eq 'ps') { my $count = 1 + $prev->[0]{val} =~ s/(p[.]?)/$1/gi; $prev->[0]{val} =~ /^(p[.]?).*(s[.]?[:]?)/; $self->[0]{val} = $1 x $count . $2; } elsif ($self->[0]{type} eq 'bul') { # do nothing } elsif (@$self>@$prev) { # going down level(s) for $level (0..$#$prev) { @{$self->[$level]}{'val','nval'} = @{$prev->[$level]}{'val','nval'}; } for $level (@$prev..$#$self) { _reset($self->[$level]); } } else # same level or going up { for $level (0..$#$self) { @{$self->[$level]}{'val','nval'} = @{$prev->[$level]}{'val','nval'}; } _incr($self->[-1]) } } sub _incr { no warnings "all"; if ($_[0]{type} eq 'rom') { $_[0]{val} = toRoman(++$_[0]{nval},$_[0]{val}); } else { $_[0]{val}++ unless $_[0]{type} eq 'let' && $_[0]{val}=~/Z/i; } } sub _reset { no warnings "all"; if ($_[0]{type} eq 'rom') { $_[0]{val} = toRoman($_[0]{nval}=1,$_[0]{val}); } elsif ($_[0]{type} eq 'let') { $_[0]{val} = $_[0]{val} =~ /[A-Z]/ ? 'A' : 'a'; } else { $_[0]{val} = 1; } } sub stringify { my ($self) = @_; my ($str, $level) = (""); for $level (@$self) { no warnings "all"; $str .= join "", @{$level}{'pre','val','post'}; } return $str; } sub val { my ($self, $i) = @_; return $self->[$i]{val}; } sub fields { return scalar @{$_[0]} } sub field { my ($self, $i, $newval) = @_; $self->[$i]{type} = $newval if @_>2; return $self->[$i]{type}; } sub signature { no warnings "all"; my ($self) = @_; my ($str, $level) = (""); for $level (@$self) { $level->{type} ||= ""; $str .= join "", $level->{pre}, ($level->{type} =~ /rom|let/ ? "romlet" : $level->{type}), $level->{post}; } return $str; } sub length { length $_[0]->stringify } sub empty { 0 } 1; Text-Autoformat-1.74/lib/Text/Autoformat/NullHang.pm000644 000765 000024 00000000514 12626343224 022631 0ustar00neilbstaff000000 000000 package Text::Autoformat::NullHang; $Text::Autoformat::NullHang::VERSION = '1.74'; use 5.006; use strict; use warnings; sub new { bless {}, $_[0] } sub stringify { "" } sub length { 0 } sub incr {} sub empty { 1 } sub signature { "" } sub fields { return 0 } sub field { return "" } sub val { return "" } 1;