1package Text::Pipe::Repeat; 2 3use warnings; 4use strict; 5 6 7our $VERSION = '0.10'; 8 9 10use base 'Text::Pipe::Base'; 11 12 13__PACKAGE__->mk_scalar_accessors(qw(times join)); 14 15 16use constant DEFAULTS => ( 17 times => 2, 18 join => '', 19); 20 21 22sub filter_single { 23 my ($self, $input) = @_; 24 my $output = ''; 25 26 # temp variables in case we have to loop many times, in which case 27 # repeated trips to the accessors would be inefficient. 28 29 my $times = $self->times; 30 my $join = $self->join; 31 32 for (1..$times) { 33 $output .= $input; 34 $output .= $join unless $_ eq $times; 35 } 36 $output; 37} 38 39 401; 41 42 43__END__ 44 45 46 47=head1 NAME 48 49Text::Pipe::Repeat - Common text filter API 50 51=head1 SYNOPSIS 52 53 Text::Pipe::Repeat->new(times => 2, join => "\n"); 54 55=head1 DESCRIPTION 56 57This is a pipe segment that takes input, repeats it a given number of times 58(default: 2) and join the repeated strings with a given value (default: empty 59string). 60 61=head1 METHODS 62 63=over 4 64 65=item C<clear_join> 66 67 $obj->clear_join; 68 69Clears the value that indicates how the repeated input should be joined. 70 71=item C<clear_times> 72 73 $obj->clear_times; 74 75Clears the value that indicates how many times the input should be repeated. 76 77=item C<filter_single> 78 79Implements the actual segment filter that acts upon a single string. It takes 80an input string, repeats it a number of times indicated by C<times()> and 81joins the repeated strings with the value of C<join()>, then returns it. 82 83=item C<join> 84 85 my $value = $obj->join; 86 $obj->join($value); 87 88A basic getter/setter method. The value indicates how the repeated input 89should be joined. If called without an argument, it returns the value. If 90called with a single argument, it sets the value. 91 92=item C<join_clear> 93 94Synonym for C<clear_join()>. 95 96=item C<times> 97 98 my $value = $obj->times; 99 $obj->times($value); 100 101A basic getter/setter method. The value indicates how many times the input 102should be repeated. If called without an argument, it returns the value. If 103called with a single argument, it sets the value. 104 105=item C<times_clear> 106 107Synonym for C<clear_times()>. 108 109=back 110 111Text::Pipe::Repeat inherits from L<Text::Pipe::Base>. 112 113The superclass L<Text::Pipe::Base> defines these methods and functions: 114 115 new(), bit_or(), filter(), init() 116 117The superclass L<Class::Accessor::Complex> defines these methods and 118functions: 119 120 mk_abstract_accessors(), mk_array_accessors(), mk_boolean_accessors(), 121 mk_class_array_accessors(), mk_class_hash_accessors(), 122 mk_class_scalar_accessors(), mk_concat_accessors(), 123 mk_forward_accessors(), mk_hash_accessors(), mk_integer_accessors(), 124 mk_new(), mk_object_accessors(), mk_scalar_accessors(), 125 mk_set_accessors(), mk_singleton() 126 127The superclass L<Class::Accessor> defines these methods and functions: 128 129 _carp(), _croak(), _mk_accessors(), accessor_name_for(), 130 best_practice_accessor_name_for(), best_practice_mutator_name_for(), 131 follow_best_practice(), get(), make_accessor(), make_ro_accessor(), 132 make_wo_accessor(), mk_accessors(), mk_ro_accessors(), 133 mk_wo_accessors(), mutator_name_for(), set() 134 135The superclass L<Class::Accessor::Installer> defines these methods and 136functions: 137 138 install_accessor() 139 140The superclass L<Class::Accessor::Constructor> defines these methods and 141functions: 142 143 _make_constructor(), mk_constructor(), mk_constructor_with_dirty(), 144 mk_singleton_constructor() 145 146The superclass L<Data::Inherited> defines these methods and functions: 147 148 every_hash(), every_list(), flush_every_cache_by_key() 149 150The superclass L<Class::Accessor::Constructor::Base> defines these methods 151and functions: 152 153 STORE(), clear_dirty(), clear_hygienic(), clear_unhygienic(), 154 contains_hygienic(), contains_unhygienic(), delete_hygienic(), 155 delete_unhygienic(), dirty(), dirty_clear(), dirty_set(), 156 elements_hygienic(), elements_unhygienic(), hygienic(), 157 hygienic_clear(), hygienic_contains(), hygienic_delete(), 158 hygienic_elements(), hygienic_insert(), hygienic_is_empty(), 159 hygienic_size(), insert_hygienic(), insert_unhygienic(), 160 is_empty_hygienic(), is_empty_unhygienic(), set_dirty(), 161 size_hygienic(), size_unhygienic(), unhygienic(), unhygienic_clear(), 162 unhygienic_contains(), unhygienic_delete(), unhygienic_elements(), 163 unhygienic_insert(), unhygienic_is_empty(), unhygienic_size() 164 165The superclass L<Tie::StdHash> defines these methods and functions: 166 167 CLEAR(), DELETE(), EXISTS(), FETCH(), FIRSTKEY(), NEXTKEY(), SCALAR(), 168 TIEHASH() 169 170=head1 BUGS AND LIMITATIONS 171 172No bugs have been reported. 173 174Please report any bugs or feature requests through the web interface at 175L<http://rt.cpan.org>. 176 177=head1 INSTALLATION 178 179See perlmodinstall for information and options on installing Perl modules. 180 181=head1 AVAILABILITY 182 183The latest version of this module is available from the Comprehensive Perl 184Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN 185site near you. Or see L<http://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>. 186 187The development version lives at L<http://github.com/hanekomu/text-pipe/>. 188Instead of sending patches, please fork this project using the standard git 189and github infrastructure. 190 191=head1 AUTHORS 192 193Marcel GrE<uuml>nauer, C<< <marcel@cpan.org> >> 194 195=head1 COPYRIGHT AND LICENSE 196 197Copyright 2007-2009 by the authors. 198 199This library is free software; you can redistribute it and/or modify 200it under the same terms as Perl itself. 201 202=cut 203 204