← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:15 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Contrib/MailerContrib/Change.pm
StatementsExecuted 13 statements in 1.04ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11117µs31µsFoswiki::Contrib::MailerContrib::Change::::BEGIN@12Foswiki::Contrib::MailerContrib::Change::BEGIN@12
11114µs41µsFoswiki::Contrib::MailerContrib::Change::::BEGIN@14Foswiki::Contrib::MailerContrib::Change::BEGIN@14
11111µs15µsFoswiki::Contrib::MailerContrib::Change::::BEGIN@13Foswiki::Contrib::MailerContrib::Change::BEGIN@13
1115µs5µsFoswiki::Contrib::MailerContrib::Change::::BEGIN@16Foswiki::Contrib::MailerContrib::Change::BEGIN@16
1114µs4µsFoswiki::Contrib::MailerContrib::Change::::BEGIN@17Foswiki::Contrib::MailerContrib::Change::BEGIN@17
1114µs4µsFoswiki::Contrib::MailerContrib::Change::::BEGIN@18Foswiki::Contrib::MailerContrib::Change::BEGIN@18
0000s0sFoswiki::Contrib::MailerContrib::Change::::expandDiffFoswiki::Contrib::MailerContrib::Change::expandDiff
0000s0sFoswiki::Contrib::MailerContrib::Change::::expandHTMLFoswiki::Contrib::MailerContrib::Change::expandHTML
0000s0sFoswiki::Contrib::MailerContrib::Change::::expandPlainFoswiki::Contrib::MailerContrib::Change::expandPlain
0000s0sFoswiki::Contrib::MailerContrib::Change::::expandVariablesFoswiki::Contrib::MailerContrib::Change::expandVariables
0000s0sFoswiki::Contrib::MailerContrib::Change::::mergeFoswiki::Contrib::MailerContrib::Change::merge
0000s0sFoswiki::Contrib::MailerContrib::Change::::newFoswiki::Contrib::MailerContrib::Change::new
0000s0sFoswiki::Contrib::MailerContrib::Change::::stringifyFoswiki::Contrib::MailerContrib::Change::stringify
Call graph for these subroutines as a Graphviz dot language file.
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
6Object that represents a change to a topic.
7
8=cut
9
10package Foswiki::Contrib::MailerContrib::Change;
11
12233µs245µ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
use strict;
# spent 31µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@12 # spent 14µs making 1 call to strict::import
13226µs220µ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
use warnings;
# spent 15µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@13 # spent 5µs making 1 call to warnings::import
14228µs268µ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
use Assert;
# spent 41µs making 1 call to Foswiki::Contrib::MailerContrib::Change::BEGIN@14 # spent 27µs making 1 call to Exporter::import
15
16220µs15µ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
use Foswiki ();
17226µs14µ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
use Foswiki::Plugins ();
182904µs14µ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
use Foswiki::Time ();
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
28Construct a new change object.
29
30=cut
31
32sub 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
55sub 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
66Merge another change record with this one, so that the combined
67record is a reflection of both changes.
68
69=cut
70
71sub 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
92Expand an HTML template using the values in this change. The following
93keys are expanded: %<nop>WEB%, %<nop>TOPIC%, %<nop>AUTHOR%, %<nop>TIME%,
94%<nop>REVISION%, %<nop>BASE_REV%, %<nop>CUR_REV%, %<nop>TEXTHEAD%.
95
96Returns the expanded template.
97
98=cut
99
100sub 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
132Generate a plaintext version of this change.
133
134=cut
135
136sub 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
163Generate a unified diff version of this change.
164
165=cut
166
167sub 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
200Expand an template using the values in this change. The following
201keys 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
214sub 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
25112µs1;
252__END__