Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plurals.pm |
Statements | Executed 103 statements in 997µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
22 | 1 | 1 | 415µs | 519µs | singularForm | Foswiki::Plurals::
28 | 7 | 1 | 65µs | 65µs | CORE:subst (opcode) | Foswiki::Plurals::
22 | 1 | 1 | 39µs | 39µs | CORE:match (opcode) | Foswiki::Plurals::
1 | 1 | 1 | 35µs | 46µs | BEGIN@13 | Foswiki::Plurals::
1 | 1 | 1 | 31µs | 66µs | BEGIN@14 | Foswiki::Plurals::
1 | 1 | 1 | 27µs | 99µs | BEGIN@15 | Foswiki::Plurals::
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::Plurals | ||||
6 | |||||
7 | Handle conversion of plural topic names to singular form. | ||||
8 | |||||
9 | =cut | ||||
10 | |||||
11 | package Foswiki::Plurals; | ||||
12 | |||||
13 | 2 | 63µs | 2 | 58µs | # spent 46µs (35+12) within Foswiki::Plurals::BEGIN@13 which was called:
# once (35µs+12µs) by Foswiki::Render::_renderWikiWord at line 13 # spent 46µs making 1 call to Foswiki::Plurals::BEGIN@13
# spent 12µs making 1 call to strict::import |
14 | 2 | 56µs | 2 | 101µs | # spent 66µs (31+35) within Foswiki::Plurals::BEGIN@14 which was called:
# once (31µs+35µs) by Foswiki::Render::_renderWikiWord at line 14 # spent 66µs making 1 call to Foswiki::Plurals::BEGIN@14
# spent 35µs making 1 call to warnings::import |
15 | 2 | 347µs | 2 | 171µs | # spent 99µs (27+72) within Foswiki::Plurals::BEGIN@15 which was called:
# once (27µs+72µs) by Foswiki::Render::_renderWikiWord at line 15 # spent 99µs making 1 call to Foswiki::Plurals::BEGIN@15
# spent 72µs making 1 call to Assert::import |
16 | |||||
17 | =begin TML | ||||
18 | |||||
19 | ---++ StaticMethod singularForm($web, $pluralForm) -> $singularForm | ||||
20 | |||||
21 | Try to singularise plural topic name. | ||||
22 | * =$web= - the web the topic must be in | ||||
23 | * =$pluralForm= - topic name | ||||
24 | Returns undef if no singular form exists, otherwise returns the | ||||
25 | singular form of the topic | ||||
26 | |||||
27 | I18N - Only apply plural processing if site language is English, or | ||||
28 | if a built-in English-language web. Plurals | ||||
29 | apply to names ending in 's', where topic doesn't exist with plural | ||||
30 | name. | ||||
31 | |||||
32 | Note that this is highly langauge specific, and need to be enabled | ||||
33 | on a per-installation basis with $Foswiki::cfg{PluralToSingular}. | ||||
34 | |||||
35 | =cut | ||||
36 | |||||
37 | # spent 519µs (415+104) within Foswiki::Plurals::singularForm which was called 22 times, avg 24µs/call:
# 22 times (415µs+104µs) by Foswiki::Render::_renderWikiWord at line 610 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Render.pm, avg 24µs/call | ||||
38 | 96 | 527µs | my ( $web, $pluralForm ) = @_; | ||
39 | 22 | 43µs | $web =~ s#\.#/#go; # spent 43µs making 22 calls to Foswiki::Plurals::CORE:subst, avg 2µs/call | ||
40 | |||||
41 | # Plural processing only if enabled in configure or one of the | ||||
42 | # distributed webs | ||||
43 | return | ||||
44 | unless ( $Foswiki::cfg{PluralToSingular} | ||||
45 | or $web eq $Foswiki::cfg{UsersWebName} | ||||
46 | or $web eq $Foswiki::cfg{SystemWebName} ); | ||||
47 | 22 | 39µs | return unless ( $pluralForm =~ /s$/ ); # spent 39µs making 22 calls to Foswiki::Plurals::CORE:match, avg 2µs/call | ||
48 | |||||
49 | # Topic name is plural in form | ||||
50 | my $singularForm = $pluralForm; | ||||
51 | 1 | 2µs | $singularForm =~ s/ies$/y/; # plurals like policy / policies # spent 2µs making 1 call to Foswiki::Plurals::CORE:subst | ||
52 | 1 | 2µs | $singularForm =~ s/sses$/ss/; # plurals like address / addresses # spent 2µs making 1 call to Foswiki::Plurals::CORE:subst | ||
53 | 1 | 3µs | $singularForm =~ s/ches$/ch/; # plurals like search / searches # spent 3µs making 1 call to Foswiki::Plurals::CORE:subst | ||
54 | 1 | 3µs | $singularForm =~ s/(oes|os)$/o/; # plurals like veto / vetoes # spent 3µs making 1 call to Foswiki::Plurals::CORE:subst | ||
55 | 1 | 5µs | $singularForm =~ s/(?<=[Xx])es$//; # plurals like box / boxes # spent 5µs making 1 call to Foswiki::Plurals::CORE:subst | ||
56 | 1 | 8µs | $singularForm =~ s/(?<=[^s])s$//; # others, excluding ss like address(es) # spent 8µs making 1 call to Foswiki::Plurals::CORE:subst | ||
57 | return $singularForm; | ||||
58 | } | ||||
59 | |||||
60 | 1 | 4µs | 1; | ||
61 | __END__ | ||||
# spent 39µs within Foswiki::Plurals::CORE:match which was called 22 times, avg 2µs/call:
# 22 times (39µs+0s) by Foswiki::Plurals::singularForm at line 47, avg 2µs/call | |||||
# spent 65µs within Foswiki::Plurals::CORE:subst which was called 28 times, avg 2µs/call:
# 22 times (43µs+0s) by Foswiki::Plurals::singularForm at line 39, avg 2µs/call
# once (8µs+0s) by Foswiki::Plurals::singularForm at line 56
# once (5µs+0s) by Foswiki::Plurals::singularForm at line 55
# once (3µs+0s) by Foswiki::Plurals::singularForm at line 54
# once (3µs+0s) by Foswiki::Plurals::singularForm at line 53
# once (2µs+0s) by Foswiki::Plurals::singularForm at line 51
# once (2µs+0s) by Foswiki::Plurals::singularForm at line 52 |