File Coverage

blib/lib/Dotiac/DTL/Tag/widthratio.pm
Criterion Covered Total %
statement 76 82 92.6
branch 6 12 50.0
condition 1 3 33.3
subroutine 12 14 85.7
pod 11 11 100.0
total 106 122 86.8


line stmt bran cond sub pod time code
1             #widthratio.pm
2             #Last Change: 2009-01-19
3             #Copyright (c) 2009 Marc-Seabstian "Maluku" Lucksch
4             #Version 0.8
5             ####################
6             #This file is part of the Dotiac::DTL project.
7             #http://search.cpan.org/perldoc?Dotiac::DTL
8             #
9             #widthratio.pm is published under the terms of the MIT license, which
10             #basically means "Do with it whatever you want". For more information, see the
11             #license.txt file that should be enclosed with libsofu distributions. A copy of
12             #the license is (at the time of writing) also available at
13             #http://www.opensource.org/licenses/mit-license.php .
14             ###############################################################################
15            
16             package Dotiac::DTL::Tag::widthratio;
17 11     11   61 use base qw/Dotiac::DTL::Tag/;
  11         24  
  11         897  
18 11     11   69 use strict;
  11         19  
  11         352  
19 11     11   56 use warnings;
  11         23  
  11         23350  
20             require Scalar::Util;
21            
22             our $VERSION = 0.8;
23            
24             sub new {
25 2     2 1 3 my $class=shift;
26 2         8 my $self={p=>shift()};
27 2         8 bless $self,$class;
28 2         5 my $name=shift;
29 2         9 my @arg=Dotiac::DTL::get_variables($name);
30 2 50 33     21 die "Wrong format for widthratio THISVALUE MAXVALUE 1221 \"\"" unless @arg > 2 and Scalar::Util::looks_like_number($arg[2]);
31 2         16 $self->{cur}=$arg[0];
32 2         6 $self->{max}=$arg[1];
33 2         5 $self->{width}=$arg[2];
34 2         8 return $self;
35             }
36             sub print {
37 2     2 1 4 my $self=shift;
38 2         12 print $self->{p};
39 2         8 my $cur = Dotiac::DTL::devar($self->{cur},@_);
40 2 50       9 $cur=0 unless Scalar::Util::looks_like_number($cur);
41 2         8 my $max = Dotiac::DTL::devar($self->{max},@_);
42 2 50       11 $max=$cur+1 unless Scalar::Util::looks_like_number($max);
43 2         12 print int($self->{width}*$cur/$max+0.5);
44 2         16 $self->{n}->print(@_);
45             }
46             sub string {
47 2     2 1 3 my $self=shift;
48 2         9 my $cur = Dotiac::DTL::devar($self->{cur},@_);
49 2 50       9 $cur=0 unless Scalar::Util::looks_like_number($cur);
50 2         9 my $max = Dotiac::DTL::devar($self->{max},@_);
51 2 50       8 $max=$cur+1 unless Scalar::Util::looks_like_number($max);
52 2         20 return $self->{p}.int($self->{width}*$cur/$max+0.5).$self->{n}->string(@_);
53            
54             }
55             sub perl {
56 2     2 1 5 my $self=shift;
57 2         4 my $fh=shift;
58 2         3 my $id=shift;
59 2         16 $self->SUPER::perl($fh,$id,@_);
60 2         4 print $fh "my ";
61 2         13 print $fh (Data::Dumper->Dump([$self->{width}],["\$width$id"]));
62 2         74 print $fh "my ";
63 2         12 print $fh (Data::Dumper->Dump([$self->{max}],["\$wmax$id"]));
64 2         70 print $fh "my ";
65 2         11 print $fh (Data::Dumper->Dump([$self->{cur}],["\$wcur$id"]));
66 2 50       78 return $self->{n}->perl($fh,$id+1,@_) if $self->{n};
67 0         0 return $id;
68             }
69             sub perlprint {
70 2     2 1 5 my $self=shift;
71 2         4 my $fh=shift;
72 2         3 my $id=shift;
73 2         3 my $level=shift;
74 2         11 $self->SUPER::perlprint($fh,$id,$level,@_);
75 2         7 print $fh "\t"x$level,"my \$cur$id = Dotiac::DTL::devar(\$wcur$id,\$vars,\$escape,\@_);\n";
76 2         6 print $fh "\t"x$level,"\$cur$id=0 unless Scalar::Util::looks_like_number(\$cur$id);\n";
77 2         5 print $fh "\t"x$level,"my \$max$id = Dotiac::DTL::devar(\$wmax$id,\$vars,\$escape,\@_);\n";
78 2         6 print $fh "\t"x$level,"\$max$id=\$cur$id+1 unless Scalar::Util::looks_like_number(\$max$id);\n";
79 2         6 print $fh "\t"x$level,"print int(\$width$id*\$cur$id/\$max$id+0.5);\n";
80 2         10 return $self->{n}->perlprint($fh,$id+1,$level,@_);
81             }
82             sub perlstring {
83 2     2 1 4 my $self=shift;
84 2         4 my $fh=shift;
85 2         2 my $id=shift;
86 2         4 my $level=shift;
87 2         14 $self->SUPER::perlstring($fh,$id,$level,@_);
88 2         9 print $fh "\t"x$level,"my \$cur$id = Dotiac::DTL::devar(\$wcur$id,\$vars,\$escape,\@_);\n";
89 2         9 print $fh "\t"x$level,"\$cur$id=0 unless Scalar::Util::looks_like_number(\$cur$id);\n";
90 2         7 print $fh "\t"x$level,"my \$max$id = Dotiac::DTL::devar(\$wmax$id,\$vars,\$escape,\@_);\n";
91 2         8 print $fh "\t"x$level,"\$max$id=\$cur$id+1 unless Scalar::Util::looks_like_number(\$max$id);\n";
92 2         7 print $fh "\t"x$level,"\$r.=int(\$width$id*\$cur$id/\$max$id+0.5);\n";
93 2         13 return $self->{n}->perlstring($fh,$id+1,$level,@_);
94             }
95             sub perlcount {
96 0     0 1 0 my $self=shift;
97 0         0 my $id=shift;
98 0         0 return $self->{n}->perlcount($id+1);
99             }
100             sub perleval {
101 2     2 1 5 my $self=shift;
102 2         3 my $fh=shift;
103 2         4 my $id=shift;
104 2         7 return $self->{n}->perleval($fh,$id+1,@_);
105             }
106             sub perlinit {
107 2     2 1 5 my $self=shift;
108 2         5 my $fh=shift;
109 2         2 my $id=shift;
110 2         14 return $self->{n}->perlinit($fh,$id+1,@_);
111             }
112             sub next {
113 2     2 1 5 my $self=shift;
114 2         8 $self->{n}=shift;
115             }
116             sub eval {
117 0     0 1   my $self=shift;
118 0           $self->{n}->eval(@_);
119             }
120             1;
121            
122             __END__