WebEditor/OldFeatures/PrintTemplates.pm

filter: Statementstmt 28.2% 11 / 39 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 3 / 4 Podpod 0.0% 0 / 1 totaltotal 22.5% 14 / 62 CC 7 SCAR 36.8
CC
7
Cov
21%
makehtmlpage_print_templates
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 39.5
« WebEditor/OldController/Msg.pm ↑ Summary WE/DB/ComplexUser/AuthUnix.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: PrintTemplates.pm,v 1.1 2005/01/29 16:48:12 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2005 Slaven Rezic. All rights reserved.
8 # This package is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
10 #
11 # Mail: eserte@users.sourceforge.net
12 # WWW: http://www.sourceforge.net/projects/we-framework
13 #
14  
15 package WebEditor::OldFeatures::PrintTemplates;
16  
17 =head1 NAME
18  
19 WebEditor::OldFeatures::PrintTemplates - additionally process print templates
20  
21 =head1 SYNOPSIS
22  
23 =head1 DESCRIPTION
24  
25 Add the method makehtmlpage_print_templates to
26 L<WebEditor::OldController>. This method is normally accessed as the
27 C<print_templates> hook in the C<makehtmlhook> feature, see
28 L<configuration.pod>.
29  
30 =head1 AUTHOR
31  
32 Slaven Rezic.
33  
34 =cut
35  
36 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
39  
40 1 ▶use mixin::with 'WebEditor::OldController';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # add mixin'ed methods here
43  
44 0 ▶sub makehtmlpage_print_templates {
Subroutine makehtmlpage_print_templates: not called CC=7 SCAR=40.3
Pod undocumented
45 0 my $self = shift;
46  
47 0 my $root = $self->Root;
48 0 my $objdb = $root->ObjDB;
49 0 my $c = $self->C;
50  
51 0 my(%args) = @_;
52  
53 0 ▶ my $lang = $args{lang} || $c->project->sitelanguages->[0];
Condition0%0/3
$args{'lang'} || $c->project->sitelanguages->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'lang'} || $c->project->sitelanguages->[0]
$args{'lang'} $c->project->sitelanguages->[0]
Truth table0%0/3
A || B
A= $args{'lang'}B= $c->project->sitelanguages->[0]
ABresult
1X1
011
000
54 0 ▶ my $basedir = $args{basedir} || $c->paths->pubhtmldir;
Condition0%0/3
$args{'basedir'} || $c->paths->pubhtmldir
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'basedir'} || $c->paths->pubhtmldir
$args{'basedir'} $c->paths->pubhtmldir
Truth table0%0/3
A || B
A= $args{'basedir'}B= $c->paths->pubhtmldir
ABresult
1X1
011
000
55  
56 my($id, $mainid, $template, $addtemplatevars) =
57 0 @args{qw(id mainid template addtemplatevars)};
58  
59 0 my $msg = "";
60  
61 # gibt es von diesem Template noch ein Print-Template?
62 # dann nochmal die Print-Version erzeugen:
63 0 my $printtemplate = $template;
64 0 $printtemplate =~ s/\.tpl\.html$/_p\.tpl\.html/;
65 0 ▶ if (-e $c->paths->site_templatebase."/$printtemplate") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $c->paths->site_templatebase . "/$printtemplate") 0 0 0
66 0 $msg .= "$printtemplate --- ";
67 0 require File::Compare;
68 0 my $phtmlfile = $basedir."/html/".$lang."/".$mainid."_p.html";
69 0 $msg .= "$phtmlfile --- ";
70 0 my $tmpfile = "$phtmlfile~";
71  
72 0 my $converter = $self->get_fh_charset_converter;
73  
74 0 ▶ open(HTML, ">$tmpfile") or die("Publish: can't write to $tmpfile: $!");
Branch: 1 branch
BranchTrueFalseTotal
open HTML, ">$tmpfile" or die "Publish: can't write to ${tmpfile}: $!" 0 0 0
75 0 $converter->(\*HTML);
76 0 $self->_tpl("site", $printtemplate, $addtemplatevars, \*HTML);
77 0 close HTML;
78  
79 0 ▶ if (File::Compare::compare($phtmlfile, $tmpfile) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (File::Compare::compare($phtmlfile, $tmpfile) == 0) { } 0 0 0
80 # no change --- delete $tmpfile
81 0 unlink $tmpfile;
82 0 $msg .= " ($lang: keine Änderung) ";
83 } else {
84 0 unlink $phtmlfile; # do not fail --- maybe file does not exist
85 0 ▶ rename $tmpfile, $phtmlfile or die "Can't rename $tmpfile to $phtmlfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $tmpfile, $phtmlfile or die "Can't rename $tmpfile to ${phtmlfile}: $!" 0 0 0
86 }
87  
88 }
89  
90 0 return { Message => $msg };
91 }
92  
93 1 1;
« WebEditor/OldController/Msg.pm ↑ Summary WE/DB/ComplexUser/AuthUnix.pm »