WE_Frontend/Plugin/KeywordIndex.pm

filter: Statementstmt 42.5% 20 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 6 / 10 Podpod 66.6% 2 / 3 totaltotal 43.0% 28 / 65 CC 5 SCAR 15.8
CC
5
Cov
39%
__ANON__
12.0
gather_keywords
6.0
array
6.0
CRAP 4.9
« WE/Util/Date.pm ↑ Summary WE_Frontend/Plugin/Navigation/Object.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: KeywordIndex.pm,v 1.3 2004/01/28 16:49:59 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2003 Slaven Rezic.
8 # This is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License, see the file COPYING.
10  
11 #
12 # Mail: slaven@rezic.de
13 # WWW: http://we-framework.sourceforge.net
14 #
15  
16 package WE_Frontend::Plugin::KeywordIndex;
17 1 ▶use base qw(Template::Plugin);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use WE::Util::LangString qw(langstring);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use WE_Frontend::Plugin::WE_Navigation;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
27  
28 =head1 NAME
29  
30 WE_Frontend::Plugin::KeywordIndex - gather site keywords
31  
32 =head1 SYNOPSIS
33  
34 my $t = Template->new({PLUGIN_BASE => "WE_Frontend::Plugin"});
35  
36 [% USE KeywordIndex %]
37 [% SET keywords = KeywordIndex.array() %]
38  
39 =head1 DESCRIPTION
40  
41 Gather keywords and return them to the templating system.
42  
43 =head2 METHODS
44  
45 =over
46  
47 =cut
48  
49 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
50 0 my($class, $context, $params) = @_;
51 0 my $n = WE_Frontend::Plugin::WE_Navigation->new($context, $params);
52 0 my $self = { WE_Navigation => $n,
53 Context => $context,
54 };
55 0 bless $self, $class;
56 }
57  
58 # XXX Possible args:
59 # * $lang
60 # * keyword-normalizer as a anonymous subroutine
61 # * restrictions (use is_released_object or such?)
62 0 ▶sub gather_keywords {
Subroutine gather_keywords: not called CC=2 SCAR=17.9
Pod undocumented
63 0 my($self, $rootid, %args) = @_;
64 0 my $wen = $self->{WE_Navigation};
65 0 my $objdb = $wen->{ObjDB};
66 0 ▶ my $lang = $wen->{Context}->stash->get("lang") || "en";
Condition0%0/2
$wen->{'Context'}->stash->get('lang') || 'en'
l!l
00
MC/DC0%0/1
$wen->{'Context'}->stash->get('lang') || 'en'
$wen->{'Context'}->stash->get('lang')
Truth table0%0/2
A
A= $wen->{'Context'}->stash->get('lang')
Aresult
11
00
67 0 $rootid = $objdb->root_object->Id;
68 0 my %keywords;
69 $objdb->walk($rootid,
70 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
71 0 my($id) = @_;
72 0 my $o = $objdb->get_object($id);
73 0 my $s = langstring($o->Keywords, $lang);
74 0 ▶ return if !defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
75 0 my @keywords = split /\s*,\s*/, $s;
76 0 for my $kw (@keywords) {
77 0 push @{ $keywords{$kw} },
78 {
79 Id => $id,
80 Title => langstring($o->Title, $lang),
81 Relurl => "$id.html", # XXX do not hardcode extension, use NameDB if possible
82 };
83 }
84 0 });
85 0 \%keywords;
86 }
87  
88 =item array()
89  
90 Format and output the given text definition.
91  
92 =cut
93  
94 # XXX Possible %args:
95 # * interpolate initials into the result array
96 # * sort function
97 0 ▶sub array {
Subroutine array: not called CC=2 SCAR=17.9
Pod documented
98 0 my($self) = @_;
99 0 my $keywords = $self->gather_keywords(); # XXX supply objid and %args (from params?)
100 0 my @out;
101 0 for my $kw (sort { uc $a cmp uc $b } keys %$keywords) {
102 push @out, {Keyword => $kw,
103 0 References => $keywords->{$kw},
104 };
105 }
106 0 return \@out;
107 }
108  
109 1 1;
110  
111 __END__
« WE/Util/Date.pm ↑ Summary WE_Frontend/Plugin/Navigation/Object.pm »