| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Template::Plugin::CSV; |
|
2
|
1
|
|
|
1
|
|
899
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use base qw(Template::Plugin); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1544
|
|
|
4
|
1
|
|
|
1
|
|
5372
|
use Template::Plugin; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
5
|
1
|
|
|
1
|
|
995
|
use Text::CSV; |
|
|
1
|
|
|
|
|
11844
|
|
|
|
1
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
0
|
|
|
0
|
1
|
|
my ($class, $context) = @_; |
|
11
|
0
|
|
|
|
|
|
my $csv = Text::CSV->new(); |
|
12
|
0
|
|
|
|
|
|
bless { |
|
13
|
|
|
|
|
|
|
csv => $csv, |
|
14
|
|
|
|
|
|
|
_CONTEXT => $context |
|
15
|
|
|
|
|
|
|
}, $class; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub dump { |
|
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
20
|
0
|
|
|
|
|
|
my $array = shift; |
|
21
|
0
|
|
|
|
|
|
$self->{csv}->combine(@$array); |
|
22
|
0
|
|
|
|
|
|
return $self->{csv}->string; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub dump_values { |
|
26
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
27
|
0
|
|
|
|
|
|
my $h = shift; |
|
28
|
0
|
|
|
|
|
|
my @values = values %$h; |
|
29
|
0
|
|
|
|
|
|
$self->{csv}->combine(@values); |
|
30
|
0
|
|
|
|
|
|
return $self->{csv}->string; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Template::Plugin::CSV - Plugin for generating CSV |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
[% USE CSV %] |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
[% CSV.dump(list_var) %] |
|
44
|
|
|
|
|
|
|
[% CSV.dump_values(hash_var) %] |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This is a very simple TT2 Plugin for generating CSV. A CSV object |
|
49
|
|
|
|
|
|
|
will be instantiated via the following directive: |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
[% USE CSV %] |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
There are two methods supported by the CSV object. Each will |
|
56
|
|
|
|
|
|
|
output a comma-sepeated line. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 dump() |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Given a list and dump a comma-sepearted line of its elements. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 dump_values() |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Given a hash and dump a comma-sepearte lines of its values. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 new() |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
A Template::Plugin constructor. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Kang-min Liu Egugod@gugod.orgE |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Copyright (C) 2005 Kang-min Liu, All Rights Reserved. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
|
79
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L, L |