Rhetoric/Widgets.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Rhetoric::Widgets;
2 use common::sense;
3 use aliased 'Squatting::H';
4 use Method::Signatures::Simple;
5 use File::Basename;
6 use Ouch;
7 use IO::All;
8  
9 our $widgets = H->new({
10  
11 # path in filesystem for blog metadata
12 base => '',
13  
14 # initialize the $widget object
15 init => method($config) {
16 $self->base($config->{base});
17 },
18  
19 # return a list of all positions defined by blog metadata
20 positions => method {
21 my $base = $self->base;
22 my @positions = map { basename($_) } grep { -d } <$base/widgets/*>;
23 },
24  
25 # return widget closures for a given position
26 widgets_for => method($position) {
27 my $base = $self->base;
28 my $path = "$base/widgets/$position";
29 ouch('DirectoryNotFound', $path) unless -d $path;
30 my @widgets = map { do $_ } <$path/[0-9][0-9]_*.pl>;
31 },
32  
33 # return content for widgets as a list of strings
34 content_for => method($position, $c, @args) {
35 my @content =
36 grep { defined }
37 map { $_->($c, @args) } $self->widgets_for($position);
38 }
39  
40 });
41  
42 1;
43  
44 __END__