NAME
App::Rssfilter::FromHash - a role for creating App::Rssfilter objects from a configuration hash
VERSION
version 0.07
SYNOPSIS
{
package Cool::Name;
use Role::Tiny::With;
with 'App::Rssfilter::FromHash';
sub new { ... }
sub add_group { ... }
sub add_feed { ... }
sub add_rule { ... }
};
my $cool_name = Cool::Name->from_hash(
name => 'some group',
rules => [
# add_rule will be called with ...
keyvalue_pair => 'some value',
# then ...
{
this_hashref => 'of options',
with_multiple => 'keys and values',
},
# and then ...
$already_constructed_object,
],
feeds => [
# same as rules above
# mix elements as you please
keyword_pair_for_first_feed => 'and value',
keyword_pair_for_second_feed => 'with different value',
{
feed_option1 => 'more key-value pairs',
feed_option2 => 'which will be passed as arguments',
feed_option3 => 'for the third call to add_feed',
},
],
groups => [
{
name => 'a subgroup',
# subgroups can have their own feeds, rules, and subgroups
feeds => [ ... ],
rules => [ ... ],
groups => [ ... ],
},
{
name => 'another subgroup',
feeds => [ ... ],
rules => [ ... ],
groups => [ ... ],
},
],
);
DESCRIPTION
This role will extend its receiving class with a "from_hash" method. It requires that the receiver has add_group
, add_feed
, and add_rule
methods, and accepts a name
attribute to its constructor.
METHODS
from_hash
my $receiver_instance = Receiver::Class->from_hash( %config );
Create a new instance of the receiving class (using $config{name}
as its name), then walk the hash to create subgroups and add feeds or rules to it (or its subgroups).
The hash may have four elements:
name
- name of this groupgroups
- arrayref of hashrefs for subgroups, same schema as the original hashfeeds
- arrayref of feeds to fetchrules
- arrayref of rules to apply
Bare scalars in feeds
will be collected into key-value pairs; everything else will be mapped onto the receiver's add_feed
. Likewise for rules
.
split_for_ctor
B<INTERNAL>
my @arguments_for_ctor_in_arrayrefs = $receiving_instance->split_for_ctor( @args );
Returns the elements of @args
partitioned into arrayrefs, whose contents are suitable arguments for a Moose-y constructor. Collects bare scalars in @args
with their following element into key-value pairs; arrayrefs & hashrefs are dereferenced; everthing else is taken as-is.
AUTHOR
Daniel Holz <dgholz@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Daniel Holz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.