WE_Frontend/Plugin/Teaser.pm

filter: Statementstmt 27.6% 13 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 57.1% 4 / 7 Podpod 66.6% 2 / 3 totaltotal 19.7% 19 / 96 CC 14 SCAR 36.5
CC
14
Cov
17%
content
72.0
new
30.0
old_get_teasercontent
12.0
CRAP 38.3
« WE/Util/MIME.pm ↑ Summary WE_Sample/Root.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: Teaser.pm,v 1.3 2004/10/18 15:26:20 eserte Exp $
5 # Author: Olaf Mätzner
6 #
7 # Copyright (C) 2002 Olaf Mätzner
8 # Copyright (C) 2003 Slaven Rezic
9 # This is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License, see the file COPYING.
11 #
12 # Mail: oleberlin@users.sourceforge.net
13 # Mail: eserte@users.sourceforge.net
14 #
15  
16 package WE_Frontend::Plugin::Teaser;
17 1 ▶use base qw(Template::Plugin);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
22  
23 =head1 NAME
24  
25 WE_Frontend::Plugin::Teaser - teaser support
26  
27 =head1 SYNOPSIS
28  
29 From Template-Toolkit templates:
30  
31 [%- USE t = Teaser(objid=teaserpageid) -%]
32 [%- SET teasercontent = t.content(teaser=teasernumber) -%]
33 [%- FOREACH item = teasercontent.ct -%]
34 ...
35 [%- END -%]
36  
37 =head1 DESCRIPTION
38  
39 =over
40  
41 =item Teaser(objid = pageid)
42  
43 Construct a teaser object with the specified object id.
44  
45 =item content(teaser = teaser, lang = language)
46  
47 Return the content of a requested teaser (by teaser number).
48 Optionally use the specific language. If the C<lang> variable is not
49 given, then look for the C<lang> variable in the global Template
50 stash, otherwise fallback to C<de>.
51  
52 =back
53  
54 =cut
55  
56 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
57 0 my($class, $context, $params) = @_;
58 0 ▶ $params ||= {};
Condition0%0/2
$params ||= {}
l!l
00
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
Aresult
11
00
59 0 ▶ my $objdb = $params->{objdb} || $context->stash->get("objdb");
Condition0%0/3
$params->{'objdb'} || $context->stash->get('objdb')
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'objdb'} || $context->stash->get('objdb')
$params->{'objdb'} $context->stash->get('objdb')
Truth table0%0/3
A || B
A= $params->{'objdb'}B= $context->stash->get('objdb')
ABresult
1X1
011
000
60 0 ▶ my $objid = $params->{objid} || $context->stash->get("objid");
Condition0%0/3
$params->{'objid'} || $context->stash->get('objid')
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'objid'} || $context->stash->get('objid')
$params->{'objid'} $context->stash->get('objid')
Truth table0%0/3
A || B
A= $params->{'objid'}B= $context->stash->get('objid')
ABresult
1X1
011
000
61 0 ▶ my $lang = $params->{lang} || $context->stash->get("lang");
Condition0%0/3
$params->{'lang'} || $context->stash->get('lang')
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'lang'} || $context->stash->get('lang')
$params->{'lang'} $context->stash->get('lang')
Truth table0%0/3
A || B
A= $params->{'lang'}B= $context->stash->get('lang')
ABresult
1X1
011
000
62 0 my $self = {
63 Context => $context,
64 ObjDB => $objdb,
65 ObjID => $objid,
66 Lang => $lang,
67 };
68 0 bless $self, $class;
69 }
70  
71 1 ▶use vars qw($outdata);
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 0 ▶sub content {
Subroutine content: not called CC=8 SCAR=42.8
Pod documented
74 0 my $self = shift;
75 0 ▶ my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[$#_] eq 'HASH' ? : 0 0 0
76 0 ▶ my $objid = defined $params->{objid} ? $params->{objid} : $self->{ObjID};
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{'objid'} ? : 0 0 0
77 0 my $content = $self->{ObjDB}->content($objid);
78 0 ▶ my $teaser = defined $params->{teaser} ? $params->{teaser} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{'teaser'} ? : 0 0 0
79 0 ▶ my $lang = $params->{lang} || $self->{Lang} || "de";
Condition0%0/5
$params->{'lang'} || $self->{'Lang'} || 'de'
l!l
00
$params->{"lang"} or $self->{"Lang"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'lang'} || $self->{'Lang'} || 'de'
$params->{"lang"} $self->{"Lang"}
Truth table0%0/3
A or B
A= $params->{"lang"}B= $self->{"Lang"}
ABresult
1X1
011
000
80  
81 0 $@ = "";
82 0 eval $content;
83 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
84 0 die "Error while evaluating content <$content>: $@";
85 }
86  
87 # my(@teasers) = @{ $outdata->{'data'}->{$lang}->{'ct'} };
88 # double redirection? XXX
89 0 my(@teasers) = @{ $outdata->{'data'}->{$lang}->{'ct'}->[0]->{'ct'} };
90 0 ▶ if (!defined $teasers[$teaser]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $teasers[$teaser]) 0 0 0
91 0 require Data::Dumper;
92 0 print STDERR Data::Dumper->new([$outdata, $lang, \@teasers, $teaser],['outdata','lang','teasers','teaser'])->Indent(1)->Useqq(1)->Dump;
93 0 die "There is no teaser with number <$teaser> for language <$lang>, max teaser number is <$#teasers>";
94 }
95 0 return $teasers[$teaser];
96 }
97  
98 0 ▶sub old_get_teasercontent {
Subroutine old_get_teasercontent: not called CC=3 SCAR=24.8
Pod undocumented
99 0 my $self = shift;
100 0 ▶ my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[$#_] eq 'HASH' ? : 0 0 0
101 0 my $content = $self->{ObjDB}->content($params->{'pageid'});
102 0 my $teaser = 1;#$params->{'teaser'};
103 0 my $lang = "de";#$params->{'lang'};
104 ######################
105 #
106 # $content ist hier ein String mit einem Data:Dump (aus der XX.bin datei)
107 #
108 #y $ct = '$bla = "hallo"';
109 0 ▶ eval $content or return "murks $@"; ## det jeht nich.
Branch: 1 branch
BranchTrueFalseTotal
eval $content or return "murks $@" 0 0 0
110  
111 ######################
112 # ich will ein Objekt zurückgeben
113 # so was hätt ich gerne:
114  
115 0 require Data::Dumper;
116 0 print STDERR Data::Dumper->new([$outdata],[])->Dump;
117 0 my @teasers = $outdata->{'data'}->{$lang}->{'ct'} ;
118 0 return $teasers[$teaser];
119  
120 }
« WE/Util/MIME.pm ↑ Summary WE_Sample/Root.pm »