← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:57 2011

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