File Coverage

blib/lib/WE_Frontend/Plugin/Teaser.pm
Criterion Covered Total %
statement 12 46 26.0
branch 0 14 0.0
condition 0 13 0.0
subroutine 4 7 57.1
pod 2 3 66.6
total 18 83 21.6


line stmt bran cond sub pod time code
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     1   1556 use base qw(Template::Plugin);
  1         2  
  1         88  
18              
19 1     1   7 use strict;
  1         2  
  1         41  
20 1     1   5 use vars qw($VERSION);
  1         2  
  1         219  
21             $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 variable is not
49             given, then look for the C variable in the global Template
50             stash, otherwise fallback to C.
51              
52             =back
53              
54             =cut
55              
56             sub new {
57 0     0 1   my($class, $context, $params) = @_;
58 0   0       $params ||= {};
59 0   0       my $objdb = $params->{objdb} || $context->stash->get("objdb");
60 0   0       my $objid = $params->{objid} || $context->stash->get("objid");
61 0   0       my $lang = $params->{lang} || $context->stash->get("lang");
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     1   6 use vars qw($outdata);
  1         2  
  1         525  
72              
73             sub content {
74 0     0 1   my $self = shift;
75 0 0         my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { };
76 0 0         my $objid = defined $params->{objid} ? $params->{objid} : $self->{ObjID};
77 0           my $content = $self->{ObjDB}->content($objid);
78 0 0         my $teaser = defined $params->{teaser} ? $params->{teaser} : 1;
79 0   0       my $lang = $params->{lang} || $self->{Lang} || "de";
80              
81 0           $@ = "";
82 0           eval $content;
83 0 0         if ($@) {
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'} };
  0            
90 0 0         if (!defined $teasers[$teaser]) {
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             sub old_get_teasercontent {
99 0     0 0   my $self = shift;
100 0 0         my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { };
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 0         eval $content or return "murks $@"; ## det jeht nich.
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             }