Text::Flow::Wrap(3pm)

πŸ“¦
version 0.01 Β· 2 versions
  • 0.01 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.01 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Text::Flow::Wrap ✨

okay bestie, sit down, because we're talking about Text::Flow::Wrap β€” it's a Perl module (from the User Contributed Perl Documentation, if you care about the paperwork πŸ’…) and it does flexible word wrapping for not just ASCII output. yes. the wrapping works even when your fonts are doing the absolute most. πŸ¦‹


🌸 SYNOPSIS 🌸

like, here's the vibe in code form:

use Text::Flow::Wrap;

# for regular ASCII usage ...
my $wrapper = Text::Flow::Wrap->new(
    check_width => sub { length($_[0]) < 70 },
);

# for non-ASCII usage ...
my $wrapper = Text::Flow::Wrap->new(
    check_width => sub { $pdf->get_text_width($_[0]) < 500 },
);

my $text = $wrapper->wrap($text);

see how the second one is checking $pdf->get_text_width($_[0])? that's the whole point, she doesn't assume every character is one pixel wide. main character behavior fr fr. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

so the whole purpose of this module β€” the moment, the reason she exists β€” is to give you text wrapping features without being tied down to ASCII based output and fixed-width fonts. no cap.

and why tho? because the author's needs were for sophisticated test control in PDF and GIF output formats in particular. yeah. PDFs. GIFs. the messy ones. πŸŽ€


✨ METHODS ✨

🫢 new (%params)

constructs a brand new Text::Flow::Wrap module, and the %params you hand her set the values of the attributes listed below. that's it, that's the constructor. iconic.

🫢 wrap ($text)

this method accepts a bunch of text, and then returns a new string which is wrapped to the expected width. literally that's her job. give text, get text back but wrapped. slay.


🧚 Attribute Accessors

🌈 check_width (\&code)

okay so this one is required, and it must be a CODE reference β€” no shortcuts, bestie, she will notice. it's used to determine if the width of the text is appropriate. it gets, as an argument, a string which it should check the width of. it should return a Boolean value: true if the string has not exceeded the max width, and false if it has. πŸ™ˆ

🌈 line_break ($str)

the line break character used when assembling and disassembling the text. defaults to the newline character "\n".

🌈 paragraph_boundry ($str)

the paragraph boundry marker used when disassembling the text. defaults to the string "\n".

(yes it's spelled boundry in the attribute name. we don't fix her, we love her as she is πŸ’€)

🌈 paragraph_break ($str)

the paragraph breaker used when re-assembling the text. defaults to the string "\n\n".

🌈 word_boundry ($str)

the word boundry marker used when disassembling the text. defaults to a single space character.

🌈 word_break ($str)

the paragraph breaker used when re-assembling the text. defaults to a single space character.


πŸŽ€ Paragraph Disassembling

these methods deal with breaking up the paragraphs into its parts, which can then be processed through the re-assembling methods. 🧩

these methods are mostly used internally, but more sophisticated tools might need to access them as well (see Text::Flow).

  • disassemble_paragraph
  • disassemble_paragraphs

πŸŽ€ Paragraph Reassembling

these methods deal with putting the paragraph parts back together after the disassembling methods have done their work. πŸͺ„

these methods are mostly used internally, but more sophisticated tools might need to access them as well (see Text::Flow)

  • reassemble_paragraph
  • reassemble_paragraphs

πŸ‘‘ Introspection

πŸ’œ meta

returns the Moose meta object associated with this class. look at her, looking at herself. self-aware queen. ✨


πŸ’€ BUGS πŸ’€

ngl, all complex software has bugs lurking in it, and this module is no exception. if you find a bug please either email me, or add the bug to cpan-RT. don't suffer in silence bestie, report it. 🫢


🌟 AUTHOR 🌟

Stevan Little <stevan@iinteractive.com>


Copyright 2007 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie β€” brought to you by perl v5.34.0, dated 2022-06-28. go wrap something cute. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from