domain support for feeds, factor out sc-specific bits
[scpubgit/SCS.git] / lib / SCSite / Filter.pm
CommitLineData
ebd4c292 1package SCSite::Filter;
2
3use Moo::Role;
4
5requires '_filter_stream';
6
fc436d2e 7sub new_from_site { shift->new }
8
ebd4c292 9sub callback_for {
10 my ($self, @args) = @_;
11 sub {
12 my ($stream) = @_;
13 my $config = $self->_parse_config($stream->peek);
14 $self->_filter_stream($stream, $config, @args)
15 }
16}
17
18sub _parse_config {
19 my ($self, $evt) = @_;
20 my %config = ( # adapted from CSS::Tiny, extracts -scs- prefix.
2a19b2a6 21 map { # converts -scs-foo-bar: to foo_bar
22 /^\s*-scs-([\w._-]+)\s*:\s*(.*?)\s*$/;
23 (join('_', split '-', $1), $2);
24 }
ebd4c292 25 grep { /\S/ } split /\;/, ($evt->{attrs}{style}||'')
26 );
27 s/^'(.*)'$/$1/ for values %config;
28 \%config;
29}
30
311;