| 1 | package Template::Flute::Filter::NobreakSingle; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'Template::Flute::Filter'; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Template::Flute::Filter::NobreakSingle - Replaces missing text with no-break space. | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | The nobreak_single filter replaces missing text with no-break space UTF8 character | ||
| 15 | (U+00A0). | ||
| 16 | |||
| 17 | =head1 METHODS | ||
| 18 | |||
| 19 | =head2 twig | ||
| 20 | |||
| 21 | Replaces the content of given L<XML::Twig::Elt> element with | ||
| 22 | no-break space UTF8 character if found to be empty or consisting | ||
| 23 | of white space only. | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | sub twig { | ||
| 28 | my ($self, $elt, $value) = @_; | ||
| 29 | |||
| 30 | if ($value =~ /\S/) { | ||
| 31 | $elt->set_text($value); | ||
| 32 | } | ||
| 33 | else { | ||
| 34 | $elt->set_content("\x{a0}"); | ||
| 35 | } | ||
| 36 | |||
| 37 | return $elt; | ||
| 38 | } | ||
| 39 | |||
| 40 | =head1 AUTHOR | ||
| 41 | |||
| 42 | Stefan Hornburg (Racke), <racke@linuxia.de> | ||
| 43 | |||
| 44 | =head1 LICENSE AND COPYRIGHT | ||
| 45 | |||
| 46 | Copyright 2011-2019 Stefan Hornburg (Racke) <racke@linuxia.de>. | ||
| 47 | |||
| 48 | This program is free software; you can redistribute it and/or modify it | ||
| 49 | under the terms of either: the GNU General Public License as published | ||
| 50 | by the Free Software Foundation; or the Artistic License. | ||
| 51 | |||
| 52 | See http://dev.perl.org/licenses/ for more information. | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | 1; |