NAME

BusyBird::Filter - common utilities about status filters

SYNOPSIS

    use BusyBird;
    use BusyBird::Filter qw(:all);
    
    my $drop_low_level = filter_map sub {
        my $status = shift;
        return $status->{busybird}{level} > 5 ? ($status) : ();
    };
    
    my $set_level = filter_each sub {
        my $status = shift;
        $status->{busybird}{level} = 10;
    };
    
    timeline("home")->add_filter($drop_low_level);
    timeline("home")->add_filter($set_level);

DESCRIPTION

This module provides some functions to create status filters.

A status filter is a subroutine reference to process an array-ref of statuses. See BusyBird::Timeline's add_filter() method for details about status filters.

Pre-defined Filters

Some modules provide pre-defined filters for you.

BusyBird::Filter::Twitter

Filters and transformations useful when you import statuses from Twitter.

EXPORTABLE FUNCTIONS

You can import any of the functions below. None of them is exported by default. Import ":all" to import all functions at once.

$filter = filter_each($func)

Creates a synchronous status filter that modifies each of the statuses destructively.

$func is a subroutine reference that takes a single status. For each status, $func is called like

    $func->($status)

$func is supposed to modify the given $status destructively. The result of the $filter is the list of modified statuses.

Return value from $func is ignored.

$filter = filter_map($func)

Creates a synchronous status filter that maps each of the statuses. This is similar to Perl's built-in map() function.

$func is a subroutine reference that takes a single status. For each status, $func is called like

    @mapped_statuses = $func->($status)

$func is supposed to return a list of statuses. The result of the $filter is all statuses collected from the $func.

Note that the $status given to $func is a deep clone of the original status. Even if you modify $status in $func, the original status is intact.

$filter = filter_grep($func)

Creates a synchronous status filter that picks up statuses by $func This is simalar to Perl's built-in grep() function.

$func is a subroutine reference that is called for each input status. $func is called in scalar context as in:

    $result = $func->($status)

If $result is true, that $status is passed to the next. If $result is false, the $status is filtered out.

You should not modify $status within $func.

SEE ALSO

AUTHOR

Toshio Ito <toshioito [at] cpan.org>