| 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 ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
| |||||||||||||||||||||||||
| 59 | 0 | ▶ | my $objdb = $params->{objdb} || $context->stash->get("objdb"); | ||||||||||||||||||||||
|
Condition0%0/3
$params->{'objdb'} || $context->stash->get('objdb')
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')
| |||||||||||||||||||||||||
| 60 | 0 | ▶ | my $objid = $params->{objid} || $context->stash->get("objid"); | ||||||||||||||||||||||
|
Condition0%0/3
$params->{'objid'} || $context->stash->get('objid')
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')
| |||||||||||||||||||||||||
| 61 | 0 | ▶ | my $lang = $params->{lang} || $context->stash->get("lang"); | ||||||||||||||||||||||
|
Condition0%0/3
$params->{'lang'} || $context->stash->get('lang')
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')
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 76 | 0 | ▶ | my $objid = defined $params->{objid} ? $params->{objid} : $self->{ObjID}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 77 | 0 | my $content = $self->{ObjDB}->content($objid); | |||||||||||||||||||||||
| 78 | 0 | ▶ | my $teaser = defined $params->{teaser} ? $params->{teaser} : 1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 79 | 0 | ▶ | my $lang = $params->{lang} || $self->{Lang} || "de"; | ||||||||||||||||||||||
|
Condition0%0/5
$params->{'lang'} || $self->{'Lang'} || 'de'
$params->{"lang"} or $self->{"Lang"}
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"}
| |||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||
| 81 | 0 | $@ = ""; | |||||||||||||||||||||||
| 82 | 0 | eval $content; | |||||||||||||||||||||||
| 83 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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 | } | ||||||||||||||||||||||||