Filename | /var/www/foswikidev/core/lib/Foswiki/Contrib/MailerContrib/Change.pm |
Statements | Executed 13 statements in 1.04ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 31µs | BEGIN@12 | Foswiki::Contrib::MailerContrib::Change::
1 | 1 | 1 | 14µs | 41µs | BEGIN@14 | Foswiki::Contrib::MailerContrib::Change::
1 | 1 | 1 | 11µs | 15µs | BEGIN@13 | Foswiki::Contrib::MailerContrib::Change::
1 | 1 | 1 | 5µs | 5µs | BEGIN@16 | Foswiki::Contrib::MailerContrib::Change::
1 | 1 | 1 | 4µs | 4µs | BEGIN@17 | Foswiki::Contrib::MailerContrib::Change::
1 | 1 | 1 | 4µs | 4µs | BEGIN@18 | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | expandDiff | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | expandHTML | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | expandPlain | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | expandVariables | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | merge | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | new | Foswiki::Contrib::MailerContrib::Change::
0 | 0 | 0 | 0s | 0s | stringify | Foswiki::Contrib::MailerContrib::Change::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package Foswiki::Contrib::MailerContrib::Change | ||||
6 | Object that represents a change to a topic. | ||||
7 | |||||
8 | =cut | ||||
9 | |||||
10 | package Foswiki::Contrib::MailerContrib::Change; | ||||
11 | |||||
12 | 2 | 33µs | 2 | 45µs | # spent 31µs (17+14) within Foswiki::Contrib::MailerContrib::Change::BEGIN@12 which was called:
# once (17µs+14µs) by Foswiki::Contrib::MailerContrib::BEGIN@28 at line 12 # spent 31µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@12
# spent 14µs making 1 call to strict::import |
13 | 2 | 26µs | 2 | 20µs | # spent 15µs (11+5) within Foswiki::Contrib::MailerContrib::Change::BEGIN@13 which was called:
# once (11µs+5µs) by Foswiki::Contrib::MailerContrib::BEGIN@28 at line 13 # spent 15µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@13
# spent 5µs making 1 call to warnings::import |
14 | 2 | 28µs | 2 | 68µs | # spent 41µs (14+27) within Foswiki::Contrib::MailerContrib::Change::BEGIN@14 which was called:
# once (14µs+27µs) by Foswiki::Contrib::MailerContrib::BEGIN@28 at line 14 # spent 41µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@14
# spent 27µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 20µs | 1 | 5µs | # spent 5µs within Foswiki::Contrib::MailerContrib::Change::BEGIN@16 which was called:
# once (5µs+0s) by Foswiki::Contrib::MailerContrib::BEGIN@28 at line 16 # spent 5µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@16 |
17 | 2 | 26µs | 1 | 4µs | # spent 4µs within Foswiki::Contrib::MailerContrib::Change::BEGIN@17 which was called:
# once (4µs+0s) by Foswiki::Contrib::MailerContrib::BEGIN@28 at line 17 # spent 4µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@17 |
18 | 2 | 904µs | 1 | 4µs | # spent 4µs within Foswiki::Contrib::MailerContrib::Change::BEGIN@18 which was called:
# once (4µs+0s) by Foswiki::Contrib::MailerContrib::BEGIN@28 at line 18 # spent 4µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@18 |
19 | |||||
20 | =begin TML | ||||
21 | |||||
22 | ---++ new($web, $topic, $author, $time, $rev) | ||||
23 | * =$web= - Web name | ||||
24 | * =$topic= - Topic name | ||||
25 | * =$author= - String author of change | ||||
26 | * =$time= - String time of change | ||||
27 | * =$rev= - Revision identifier | ||||
28 | Construct a new change object. | ||||
29 | |||||
30 | =cut | ||||
31 | |||||
32 | sub new { | ||||
33 | my ( $class, $web, $topic, $author, $time, $rev ) = @_; | ||||
34 | |||||
35 | my $this = bless( {}, $class ); | ||||
36 | |||||
37 | $this->{WEB} = $web; | ||||
38 | $this->{TOPIC} = $topic; | ||||
39 | my $user; | ||||
40 | |||||
41 | $this->{AUTHOR} = Foswiki::Func::getWikiName($author); | ||||
42 | |||||
43 | $this->{TIME} = $time; | ||||
44 | ASSERT( defined $rev ) if DEBUG; | ||||
45 | |||||
46 | # rev at this change | ||||
47 | $this->{CURR_REV} = $rev; | ||||
48 | |||||
49 | # previous rev | ||||
50 | $this->{BASE_REV} = $rev - 1 || 1; | ||||
51 | |||||
52 | return $this; | ||||
53 | } | ||||
54 | |||||
55 | sub stringify { | ||||
56 | my $this = shift; | ||||
57 | |||||
58 | return | ||||
59 | "$this->{WEB}.$this->{TOPIC} by $this->{AUTHOR} at $this->{TIME} from r$this->{BASE_REV} to r$this->{CURR_REV}"; | ||||
60 | } | ||||
61 | |||||
62 | =begin TML | ||||
63 | |||||
64 | ---++ merge($change) | ||||
65 | * =$change= - Change record to merge | ||||
66 | Merge another change record with this one, so that the combined | ||||
67 | record is a reflection of both changes. | ||||
68 | |||||
69 | =cut | ||||
70 | |||||
71 | sub merge { | ||||
72 | my ( $this, $other ) = @_; | ||||
73 | ASSERT( $this->isa('Foswiki::Contrib::MailerContrib::Change') ) if DEBUG; | ||||
74 | ASSERT( $other->isa('Foswiki::Contrib::MailerContrib::Change') ) if DEBUG; | ||||
75 | |||||
76 | if ( $other->{TIME} > $this->{TIME} ) { | ||||
77 | $this->{CURR_REV} = $other->{CURR_REV}; | ||||
78 | $this->{AUTHOR} = $other->{AUTHOR}; | ||||
79 | $this->{TIME} = $other->{TIME}; | ||||
80 | } | ||||
81 | |||||
82 | $this->{BASE_REV} = $other->{BASE_REV} | ||||
83 | if ( $other->{BASE_REV} < $this->{BASE_REV} ); | ||||
84 | } | ||||
85 | |||||
86 | =begin TML | ||||
87 | |||||
88 | ---++ expandHTML($template) -> string | ||||
89 | |||||
90 | * =$template= - Template to expand keys within | ||||
91 | |||||
92 | Expand an HTML template using the values in this change. The following | ||||
93 | keys are expanded: %<nop>WEB%, %<nop>TOPIC%, %<nop>AUTHOR%, %<nop>TIME%, | ||||
94 | %<nop>REVISION%, %<nop>BASE_REV%, %<nop>CUR_REV%, %<nop>TEXTHEAD%. | ||||
95 | |||||
96 | Returns the expanded template. | ||||
97 | |||||
98 | =cut | ||||
99 | |||||
100 | sub expandHTML { | ||||
101 | my ( $this, $template ) = @_; | ||||
102 | |||||
103 | unless ( defined $this->{HTML_SUMMARY} ) { | ||||
104 | if ( defined &Foswiki::Func::summariseChanges ) { | ||||
105 | $this->{HTML_SUMMARY} = | ||||
106 | Foswiki::Func::summariseChanges( $this->{WEB}, $this->{TOPIC}, | ||||
107 | $this->{BASE_REV}, $this->{CURR_REV}, 1, 1 ); | ||||
108 | } | ||||
109 | else { | ||||
110 | $this->{HTML_SUMMARY} = | ||||
111 | $Foswiki::Plugins::SESSION->{renderer} | ||||
112 | ->summariseChanges( undef, $this->{WEB}, $this->{TOPIC}, | ||||
113 | $this->{BASE_REV}, $this->{CURR_REV}, 1 ); | ||||
114 | } | ||||
115 | } | ||||
116 | |||||
117 | $template = $this->expandVariables($template); | ||||
118 | |||||
119 | $template = | ||||
120 | Foswiki::Func::expandCommonVariables( $template, $this->{TOPIC}, | ||||
121 | $this->{WEB} ); | ||||
122 | $template = Foswiki::Func::renderText($template); | ||||
123 | |||||
124 | $template =~ s/%TEXTHEAD%/$this->{HTML_SUMMARY}/g; | ||||
125 | |||||
126 | return $template; | ||||
127 | } | ||||
128 | |||||
129 | =begin TML | ||||
130 | |||||
131 | ---++ expandPlain() -> string | ||||
132 | Generate a plaintext version of this change. | ||||
133 | |||||
134 | =cut | ||||
135 | |||||
136 | sub expandPlain { | ||||
137 | my ( $this, $template ) = @_; | ||||
138 | |||||
139 | unless ( defined $this->{TEXT_SUMMARY} ) { | ||||
140 | my $s; | ||||
141 | if ( defined &Foswiki::Func::summariseChanges ) { | ||||
142 | $s = | ||||
143 | Foswiki::Func::summariseChanges( $this->{WEB}, $this->{TOPIC}, | ||||
144 | $this->{BASE_REV}, $this->{CURR_REV}, 0, 1 ); | ||||
145 | } | ||||
146 | else { | ||||
147 | $s = | ||||
148 | $Foswiki::Plugins::SESSION->{renderer} | ||||
149 | ->summariseChanges( undef, $this->{WEB}, $this->{TOPIC}, | ||||
150 | $this->{BASE_REV}, $this->{CURR_REV}, 0 ); | ||||
151 | } | ||||
152 | $s =~ s/\n/\n /gs; | ||||
153 | $s = " $s"; | ||||
154 | $this->{TEXT_SUMMARY} = $s; | ||||
155 | } | ||||
156 | |||||
157 | return $this->expandVariables( $template, 'TEXT_SUMMARY' ); | ||||
158 | } | ||||
159 | |||||
160 | =begin TML | ||||
161 | |||||
162 | ---++ expandDiff($template) -> string | ||||
163 | Generate a unified diff version of this change. | ||||
164 | |||||
165 | =cut | ||||
166 | |||||
167 | sub expandDiff { | ||||
168 | my ( $this, $template ) = @_; | ||||
169 | |||||
170 | unless ( $this->{TEXT_DIFF} ) { | ||||
171 | my $b = | ||||
172 | Foswiki::Meta->load( $Foswiki::Plugins::SESSION, $this->{WEB}, | ||||
173 | $this->{TOPIC}, $this->{CURR_REV} ); | ||||
174 | return '' unless ( $b->haveAccess('VIEW') ); | ||||
175 | my $btext = Foswiki::Serialise::serialise( $b, 'Embedded' ); | ||||
176 | $btext =~ s/^%META:TOPICINFO\{.*\}%$//; | ||||
177 | |||||
178 | return $btext if ( $this->{BASE_REV} < 1 ); | ||||
179 | |||||
180 | my $a = | ||||
181 | Foswiki::Meta->load( $Foswiki::Plugins::SESSION, $this->{WEB}, | ||||
182 | $this->{TOPIC}, $this->{BASE_REV} ); | ||||
183 | return '' unless ( $a->haveAccess('VIEW') ); | ||||
184 | my $atext = Foswiki::Serialise::serialise( $a, 'Embedded' ); | ||||
185 | $atext =~ s/^%META:TOPICINFO\{.*\}%$//; | ||||
186 | |||||
187 | require Foswiki::Merge; | ||||
188 | my $blocks = Foswiki::Merge::simpleMerge( $atext, $btext, qr/[\r\n]+/ ); | ||||
189 | $this->{TEXT_DIFF} = | ||||
190 | '<verbatim>' . join( "\n", @$blocks ) . '</verbatim>'; | ||||
191 | } | ||||
192 | |||||
193 | return $this->expandVariables( $template, 'TEXT_DIFF' ); | ||||
194 | } | ||||
195 | |||||
196 | =begin TML | ||||
197 | |||||
198 | ---++ expandVariables($template, $textHeadAttr) -> string | ||||
199 | |||||
200 | Expand an template using the values in this change. The following | ||||
201 | keys are expanded: | ||||
202 | |||||
203 | * %<nop>AUTHOR% | ||||
204 | * %<nop>BASE_REV% | ||||
205 | * %<nop>CUR_REV% | ||||
206 | * %<nop>REVISION% | ||||
207 | * %<nop>TEXTHEAD% | ||||
208 | * %<nop>TIME% | ||||
209 | * %<nop>TOPIC% | ||||
210 | * %<nop>WEB% | ||||
211 | |||||
212 | =cut | ||||
213 | |||||
214 | sub expandVariables { | ||||
215 | my ( $this, $template, $textHeadAttr ) = @_; | ||||
216 | |||||
217 | my $tim = Foswiki::Time::formatTime( $this->{TIME} ); | ||||
218 | |||||
219 | # URL-encode topic names for use of I18N topic names in plain text | ||||
220 | # DEPRECATED! DO NOT USE! | ||||
221 | $template =~ s#%URL%#%SCRIPTURL{view}%/%ENCODE{%WEB%}%/%ENCODE{%TOPIC%}%#g; | ||||
222 | |||||
223 | $template =~ s/%AUTHOR%/$this->{AUTHOR}/g; | ||||
224 | $template =~ s/%BASE_REV%/$this->{BASE_REV}/g; | ||||
225 | $template =~ s/%CUR_REV%/$this->{CURR_REV}/g; | ||||
226 | $template =~ s/%TIME%/$tim/g; | ||||
227 | $template =~ s/%WEB%/$this->{WEB}/g; | ||||
228 | $template =~ s/%TOPIC%/$this->{TOPIC}/g; | ||||
229 | $template =~ s/%TOPICNAME%/$this->{TOPIC}/g; # deprecated DO NOT USE! | ||||
230 | |||||
231 | my $frev = ''; | ||||
232 | |||||
233 | if ( $this->{CURR_REV} ) { | ||||
234 | |||||
235 | if ( $this->{CURR_REV} > 1 ) { | ||||
236 | $frev = 'r' . $this->{BASE_REV} . '->r' . $this->{CURR_REV}; | ||||
237 | } | ||||
238 | else { | ||||
239 | |||||
240 | # new _since the last notification_ | ||||
241 | $frev = 'NEW'; | ||||
242 | } | ||||
243 | } | ||||
244 | |||||
245 | $template =~ s/%REVISION%/$frev/g; | ||||
246 | $template =~ s/%TEXTHEAD%/$this->{$textHeadAttr}/g if defined $textHeadAttr; | ||||
247 | |||||
248 | return $template; | ||||
249 | } | ||||
250 | |||||
251 | 1 | 2µs | 1; | ||
252 | __END__ |