File Coverage

blib/lib/Bootylicious/Plugin/Model.pm
Criterion Covered Total %
statement 104 111 93.6
branch n/a
condition 2 4 50.0
subroutine 32 35 91.4
pod 1 1 100.0
total 139 151 92.0


line stmt bran cond sub pod time code
1             package Bootylicious::Plugin::Model;
2              
3 4     4   3021 use strict;
  4         7  
  4         173  
4 4     4   20 use warnings;
  4         5  
  4         127  
5              
6 4     4   17 use base 'Mojolicious::Plugin';
  4         6  
  4         346  
7              
8 4     4   22 use Mojolicious::Controller;
  4         6  
  4         36  
9              
10 4     4   1790 use Bootylicious::Article;
  4         12  
  4         29  
11 4     4   2128 use Bootylicious::ArticleArchive;
  4         11  
  4         29  
12 4     4   2339 use Bootylicious::ArticleArchiveSimple;
  4         10  
  4         28  
13 4     4   1945 use Bootylicious::ArticleByTagIterator;
  4         9  
  4         30  
14 4     4   2465 use Bootylicious::ArticleByQueryIterator;
  4         9  
  4         27  
15 4     4   1824 use Bootylicious::ArticleIteratorFinder;
  4         10  
  4         28  
16 4     4   1821 use Bootylicious::ArticlePager;
  4         12  
  4         33  
17 4     4   2110 use Bootylicious::Draft;
  4         10  
  4         50  
18 4     4   1874 use Bootylicious::DraftIteratorLoader;
  4         10  
  4         35  
19 4     4   1793 use Bootylicious::DraftIteratorFinder;
  4         12  
  4         92  
20 4     4   183 use Bootylicious::IteratorSearchable;
  4         98  
  4         17  
21 4     4   2213 use Bootylicious::Page;
  4         9  
  4         41  
22 4     4   1721 use Bootylicious::PageIteratorLoader;
  4         10  
  4         35  
23 4     4   119 use Bootylicious::PageIteratorFinder;
  4         8  
  4         73  
24 4     4   1836 use Bootylicious::TagCloud;
  4         10  
  4         29  
25 4     4   131 use Bootylicious::ArticleIteratorLoader;
  4         6  
  4         51  
26 4     4   197 use Bootylicious::CommentIteratorLoader;
  4         7  
  4         27  
27              
28             sub register {
29 5     5 1 293 my ($self, $app) = @_;
30              
31 5         36 my $c = Mojolicious::Controller->new(app => $app);
32              
33 5         88 my $config = $c->config;
34              
35 5         156 my $articles_root = $c->articles_root;
36 5         210 my $pages_root = $c->pages_root;
37 5         89 my $drafts_root = $c->drafts_root;
38              
39 5         63 my $page_limit = $config->{pagelimit};
40              
41             $app->helper(
42             get_pager => sub {
43 0     0   0 shift;
44 0         0 my $iterator = shift;
45 0         0 Bootylicious::ArticlePager->new(
46             limit => $page_limit,
47             iterator => $iterator,
48             @_
49             );
50             }
51 5         39 );
52              
53             $app->helper(
54             get_articles => sub {
55 5     5   12993 shift;
56              
57 5         66 Bootylicious::ArticlePager->new(
58             iterator => Bootylicious::ArticleIteratorLoader->new(
59             root => $articles_root
60             )->load,
61             limit => $page_limit,
62             @_
63             );
64             }
65 5         138 );
66              
67             $app->helper(
68             get_recent_articles => sub {
69 1     1   12 my ($self, $limit) = @_;
70              
71 1   50     4 return Bootylicious::ArticleIteratorLoader->new(
72             root => $articles_root)->load->next($limit || 5);
73             }
74 5         107 );
75              
76             $app->helper(
77             get_recent_comments => sub {
78 1     1   9 my ($self, $limit) = @_;
79 1   50     9 Bootylicious::CommentIteratorLoader->new(root => $articles_root)
80             ->load->reverse->next($limit || 5);
81             }
82 5         91 );
83              
84             $app->helper(
85             get_archive => sub {
86 3     3   170 shift;
87 3         40 Bootylicious::ArticleArchive->new(
88             articles => Bootylicious::ArticleIteratorLoader->new(
89             root => $articles_root
90             )->load,
91             @_
92             );
93             }
94 5         90 );
95              
96             $app->helper(
97             get_archive_simple => sub {
98 1     1   18 Bootylicious::ArticleArchiveSimple->new(
99             articles => Bootylicious::ArticleIteratorLoader->new(
100             root => $articles_root
101             )->load,
102             );
103             }
104 5         88 );
105              
106             $app->helper(
107             get_articles_by_tag => sub {
108 1     1   74 my $self = shift;
109 1         3 my $tag = shift;
110              
111 1         17 Bootylicious::ArticlePager->new(
112             iterator => Bootylicious::ArticleByTagIterator->new(
113             Bootylicious::ArticleIteratorLoader->new(
114             root => $articles_root
115             )->load,
116             tag => $tag
117             ),
118             limit => $page_limit,
119             @_
120             );
121             }
122 5         93 );
123              
124             $app->helper(
125             get_articles_by_query => sub {
126 0     0   0 my $self = shift;
127 0         0 my $query = shift;
128              
129 0         0 return Bootylicious::ArticleByQueryIterator->new(
130             Bootylicious::ArticleIteratorLoader->new(
131             root => $articles_root
132             )->load,
133             query => $query
134             );
135             }
136 5         95 );
137              
138             $app->helper(
139             get_tag_cloud => sub {
140 2     2   1368 Bootylicious::TagCloud->new(
141             articles => Bootylicious::ArticleIteratorLoader->new(
142             root => $articles_root
143             )->load
144             );
145             }
146 5         93 );
147              
148             $app->helper(
149             get_tags => sub {
150 0     0   0 Bootylicious::TagCloud->new(
151             articles => Bootylicious::ArticleIteratorLoader->new(
152             root => $articles_root
153             )->load
154             );
155             }
156 5         93 );
157              
158             $app->helper(
159             get_article => sub {
160 7     7   2120 my $self = shift;
161 7         303 Bootylicious::ArticleIteratorFinder->new(
162             iterator => Bootylicious::ArticleIteratorLoader->new(
163             root => $articles_root
164             )->load
165             )->find(@_);
166             }
167 5         101 );
168              
169             $app->helper(
170             get_page => sub {
171 2     2   126 my $self = shift;
172 2         5 my $name = shift;
173 2         34 Bootylicious::PageIteratorFinder->new(iterator =>
174             Bootylicious::PageIteratorLoader->new(root => $pages_root)
175             ->load)->find($name);
176             }
177 5         94 );
178              
179             $app->helper(
180             get_draft => sub {
181 1     1   75 my $self = shift;
182 1         5 my $name = shift;
183              
184 1         15 Bootylicious::DraftIteratorFinder->new(
185             iterator => Bootylicious::DraftIteratorLoader->new(
186             root => $self->drafts_root
187             )->load,
188             )->find($name);
189             }
190 5         93 );
191             }
192              
193             1;