chiark / gitweb /
Commodity location in deciles
[ypp-sc-tools.db-live.git] / yarrg / web / dumptable
1 <%doc>
2
3  This is part of the YARRG website.  YARRG is a tool and website
4  for assisting players of Yohoho Puzzle Pirates.
5
6  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7  Copyright (C) 2009 Clare Boothby
8
9   YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10   The YARRG website is covered by the GNU Affero GPL v3 or later, which
11    basically means that every installation of the website will let you
12    download the source.
13
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Affero General Public License as
16  published by the Free Software Foundation, either version 3 of the
17  License, or (at your option) any later version.
18
19  This program is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  GNU Affero General Public License for more details.
23
24  You should have received a copy of the GNU Affero General Public License
25  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28  are used without permission.  This program is not endorsed or
29  sponsored by Three Rings.
30
31
32  This Mason component is helpful for debugging and developing.  It
33  outputs plain HTML tables eg for SQL query results.  You can either:
34     <& dumptable, sth => $executed_statement_handle &>
35  in which case it will consume the results of the statement and
36  print them unconditionally, or do the equivalent of:
37     <& dumptable:start, sth => $sth,              [ qa => $qa ] &> or
38     <& dumptable:start, cols => [ 'column',... ], [ qa => $qa ] &>
39     %   my $row;
40     %   while ($row= $sth->fetchrow_hashref) {
41     <& dumptable:row, sth|cols => ..., row => $row, [ qa => $qa ] &>
42     %       do something else with $row
43     %   }
44     <& dumptable:end, [ qa => $qa ] &>
45  where if you pass $qa, dumptable will check whether debug
46  is enabled and produce no output if it isn't.  NB you don't want
47  this approach if your loop body produces output because it'll be
48  interleaved with dumptable's table.
49
50 </%doc>
51 <%args>
52 $sth
53 </%args>
54
55 <%method start>
56 <%args>
57 $sth => undef
58 $cols => $sth->{NAME}
59 $qa => undef
60 </%args>
61 %       if (!$qa || $qa->{'debug'}) {
62 <table class="data" frame=box rules=all>
63 <tr>
64 %               foreach my $field (@$cols) {
65 <th><% $field |h %>
66 %               }
67 </tr>
68 %       }
69 </%method>
70
71 <%method row>
72 <%args>
73 $sth => undef
74 $cols => $sth->{NAME}
75 $row
76 $qa => undef
77 </%args>
78 %       if (!$qa || $qa->{'debug'}) {
79 <tr>
80 %               foreach my $field (@$cols) {
81 %                       my $cell= $row->{$field};
82 <td>
83 <% $cell |h %>
84 </td>
85 %               }
86 </tr>
87 %       }
88 </%method>
89
90 <%method end>
91 <%args>
92 $qa => undef
93 </%args>
94 %       if (!$qa || $qa->{'debug'}) {
95 </table>
96 %       }
97 </%method>
98
99 <%method literal>
100 <%args>
101 $cols
102 $rows
103 $qa => undef
104 </%args>
105 <& SELF:start, cols => $cols &>
106 %       foreach my $row (@$rows) {
107 <& SELF:row, cols => $cols, row => $row &>
108 %       }
109 <& SELF:end &>
110 </%method>
111
112 <& SELF:start, sth => $sth &>
113 %       my $row;
114 %       while ($row= $sth->fetchrow_hashref) {
115 <& SELF:row, sth => $sth, row => $row &>
116 %       }
117 <& SELF:end &>