1package Text::Pipe::List::First;
2
3use warnings;
4use strict;
5use List::Util 'first';
6
7
8our $VERSION = '0.10';
9
10
11use base 'Text::Pipe::Base';
12
13
14__PACKAGE__->mk_scalar_accessors(qw(code));
15
16
17sub filter {
18    my ($self, $input) = @_;
19    return $input unless ref $input eq 'ARRAY';
20
21    # kludge because of prototype requirements
22    first { $self->code->() } @$input;
23}
24
25
261;
27
28
29__END__
30
31
32
33=head1 NAME
34
35Text::Pipe::List::First - Common text filter API
36
37=head1 SYNOPSIS
38
39    my $pipe = Text::Pipe->new('List::First', code => { $_ < 7 });
40    my $result = $pipe->filter('foo');
41
42=head1 DESCRIPTION
43
44=head1 METHODS
45
46=over 4
47
48=item C<clear_code>
49
50    $obj->clear_code;
51
52Clears the coderef.
53
54=item C<code>
55
56    my $value = $obj->code;
57    $obj->code($value);
58
59A basic getter/setter method for the coderef. If called without an argument,
60it returns the value. If called with a single argument, it sets the value.
61
62=item C<code_clear>
63
64Synonym for C<clear_code()>.
65
66=item C<filter>
67
68If the input is an array reference, it passes each element to the code
69reference. The element will be in C<$_>. Returns the first element for which
70the code reference returns a true value.
71
72If the input is a single string, it just returns that string. This is
73semantically correct - if there is only one string, it has to be the first one
74as well.
75
76=back
77
78Text::Pipe::List::First inherits from L<Text::Pipe::Base>.
79
80The superclass L<Text::Pipe::Base> defines these methods and functions:
81
82    new(), bit_or(), filter_single(), init()
83
84The superclass L<Class::Accessor::Complex> defines these methods and
85functions:
86
87    mk_abstract_accessors(), mk_array_accessors(), mk_boolean_accessors(),
88    mk_class_array_accessors(), mk_class_hash_accessors(),
89    mk_class_scalar_accessors(), mk_concat_accessors(),
90    mk_forward_accessors(), mk_hash_accessors(), mk_integer_accessors(),
91    mk_new(), mk_object_accessors(), mk_scalar_accessors(),
92    mk_set_accessors(), mk_singleton()
93
94The superclass L<Class::Accessor> defines these methods and functions:
95
96    _carp(), _croak(), _mk_accessors(), accessor_name_for(),
97    best_practice_accessor_name_for(), best_practice_mutator_name_for(),
98    follow_best_practice(), get(), make_accessor(), make_ro_accessor(),
99    make_wo_accessor(), mk_accessors(), mk_ro_accessors(),
100    mk_wo_accessors(), mutator_name_for(), set()
101
102The superclass L<Class::Accessor::Installer> defines these methods and
103functions:
104
105    install_accessor()
106
107The superclass L<Class::Accessor::Constructor> defines these methods and
108functions:
109
110    _make_constructor(), mk_constructor(), mk_constructor_with_dirty(),
111    mk_singleton_constructor()
112
113The superclass L<Data::Inherited> defines these methods and functions:
114
115    every_hash(), every_list(), flush_every_cache_by_key()
116
117The superclass L<Class::Accessor::Constructor::Base> defines these methods
118and functions:
119
120    STORE(), clear_dirty(), clear_hygienic(), clear_unhygienic(),
121    contains_hygienic(), contains_unhygienic(), delete_hygienic(),
122    delete_unhygienic(), dirty(), dirty_clear(), dirty_set(),
123    elements_hygienic(), elements_unhygienic(), hygienic(),
124    hygienic_clear(), hygienic_contains(), hygienic_delete(),
125    hygienic_elements(), hygienic_insert(), hygienic_is_empty(),
126    hygienic_size(), insert_hygienic(), insert_unhygienic(),
127    is_empty_hygienic(), is_empty_unhygienic(), set_dirty(),
128    size_hygienic(), size_unhygienic(), unhygienic(), unhygienic_clear(),
129    unhygienic_contains(), unhygienic_delete(), unhygienic_elements(),
130    unhygienic_insert(), unhygienic_is_empty(), unhygienic_size()
131
132The superclass L<Tie::StdHash> defines these methods and functions:
133
134    CLEAR(), DELETE(), EXISTS(), FETCH(), FIRSTKEY(), NEXTKEY(), SCALAR(),
135    TIEHASH()
136
137=head1 BUGS AND LIMITATIONS
138
139No bugs have been reported.
140
141Please report any bugs or feature requests through the web interface at
142L<http://rt.cpan.org>.
143
144=head1 INSTALLATION
145
146See perlmodinstall for information and options on installing Perl modules.
147
148=head1 AVAILABILITY
149
150The latest version of this module is available from the Comprehensive Perl
151Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
152site near you. Or see L<http://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.
153
154The development version lives at L<http://github.com/hanekomu/text-pipe/>.
155Instead of sending patches, please fork this project using the standard git
156and github infrastructure.
157
158=head1 AUTHORS
159
160Marcel GrE<uuml>nauer, C<< <marcel@cpan.org> >>
161
162=head1 COPYRIGHT AND LICENSE
163
164Copyright 2007-2009 by the authors.
165
166This library is free software; you can redistribute it and/or modify
167it under the same terms as Perl itself.
168
169=cut
170
171