← 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:41 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Serialise.pm
StatementsExecuted 51 statements in 1.09ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
3112.89ms3.37msFoswiki::Serialise::::getSerialiserFoswiki::Serialise::getSerialiser
32294µs7.60msFoswiki::Serialise::::serialiseFoswiki::Serialise::serialise
11124µs31µsFoswiki::Serialise::::BEGIN@4Foswiki::Serialise::BEGIN@4
11122µs196µsFoswiki::Serialise::::BEGIN@95Foswiki::Serialise::BEGIN@95
11118µs37µsFoswiki::Serialise::::BEGIN@5Foswiki::Serialise::BEGIN@5
1119µs9µsFoswiki::Serialise::::BEGIN@6Foswiki::Serialise::BEGIN@6
0000s0sFoswiki::Serialise::::convertMetaFoswiki::Serialise::convertMeta
0000s0sFoswiki::Serialise::::deserialiseFoswiki::Serialise::deserialise
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
2package Foswiki::Serialise;
3
4245µs238µs
# spent 31µs (24+7) within Foswiki::Serialise::BEGIN@4 which was called: # once (24µs+7µs) by Foswiki::Meta::BEGIN@120 at line 4
use strict;
# spent 31µs making 1 call to Foswiki::Serialise::BEGIN@4 # spent 7µs making 1 call to strict::import
5243µs255µs
# spent 37µs (18+19) within Foswiki::Serialise::BEGIN@5 which was called: # once (18µs+19µs) by Foswiki::Meta::BEGIN@120 at line 5
use warnings;
# spent 37µs making 1 call to Foswiki::Serialise::BEGIN@5 # spent 19µs making 1 call to warnings::import
62484µs19µs
# spent 9µs within Foswiki::Serialise::BEGIN@6 which was called: # once (9µs+0s) by Foswiki::Meta::BEGIN@120 at line 6
use Foswiki ();
# spent 9µs making 1 call to Foswiki::Serialise::BEGIN@6
7
8=begin TML
9
10---+ package Foswiki::Serialise
11
12API to allow structures to be serialised and de-serialized. This API will only return
13basic types like hashes and arrarys
14
15=cut
16
17#lets only load the serialiser once per execution
1812µsour %serialisers = ();
19
20#should this really be a register/request?
21
22=begin TML
23
24---++ StaticMethod serialise( $session, $value, $style ) -> $cereal
25 * =$session= Foswiki Session object
26 * =$value= the perl object we're serializing (typically a ref/obj)
27 * =$style= serialization format
28
29#TODO: do we need to use Foswiki, or can we throw a Simple exception instead?
30#I think to be reusable we catually have to throw..
31
32=cut
33
34
# spent 7.60ms (94µs+7.50) within Foswiki::Serialise::serialise which was called 3 times, avg 2.53ms/call: # 2 times (62µs+6.81ms) by Foswiki::Meta::getEmbeddedStoreForm at line 3501 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Meta.pm, avg 3.43ms/call # once (33µs+697µs) by Foswiki::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Macros/QUERY.pm:56] at line 55 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Macros/QUERY.pm
sub serialise {
351286µs my $session = shift;
36 my $value = shift;
37 my $style = shift;
38
3967.50ms return getSerialiser( $session, $style )->write( $session, $value );
# spent 4.12ms making 2 calls to Foswiki::Serialise::Embedded::write, avg 2.06ms/call # spent 3.37ms making 3 calls to Foswiki::Serialise::getSerialiser, avg 1.12ms/call # spent 11µs making 1 call to Foswiki::Serialise::Simplified::write
40}
41
42=begin TML
43
44---++ StaticMethod deserialise( $session, $cereal, $style ) -> $data
45 * =$session= Foswiki Session object
46 * =$cereal= the perl object we're serializing (typically a ref/obj)
47 * =$style= serialization format
48
49#TODO: do we need to use Foswiki, or can we throw a Simple exception instead?
50#I think to be reusable we actually have to throw..
51
52#TODO: please work out how to add _some_ autodetection of format
53
54=cut
55
56sub deserialise {
57 my $session = shift;
58 my $cereal = shift;
59 my $style = shift;
60
61 return getSerialiser( $session, $style )->read( $session, $cereal );
62}
63
64#in the event of trouble, return 'Simplified'
65
# spent 3.37ms (2.89+482µs) within Foswiki::Serialise::getSerialiser which was called 3 times, avg 1.12ms/call: # 3 times (2.89ms+482µs) by Foswiki::Serialise::serialise at line 39, avg 1.12ms/call
sub getSerialiser {
6629256µs my $session = shift;
67 my $originalstyle = shift || 'Simplified';
68
69 return $serialisers{$originalstyle}
70 if ( defined( $serialisers{$originalstyle} ) );
71
72 my $style = $originalstyle;
73 $style = 'Simplified' if ( $style eq 'default' );
74 $style = ucfirst($style);
75 my $module = "Foswiki::Serialise::$style";
76
77 eval "require $module";
# spent 200µs executing statements in string eval # spent 116µs executing statements in string eval
78 my $cereal;
79 $cereal = getSerialiser( $session, 'Simplified' ) if $@;
80
81247µs $cereal = $module->new() if ( not defined($cereal) );
# spent 26µs making 1 call to Foswiki::Serialise::Embedded::new # spent 20µs making 1 call to Foswiki::Serialise::Simplified::new
82 $serialisers{$originalstyle} = $cereal;
83 return $cereal;
84}
85
86#filter out parts of a meta object that don't make sense serialise (for example, json doesn't really like being sent a blessed object
87sub convertMeta {
88 my $savedMeta = shift;
89
90 my $meta = {};
91 $meta->{_web} = $savedMeta->web() if ( defined( $savedMeta->web() ) );
92 $meta->{_topic} = $savedMeta->topic() if ( defined( $savedMeta->topic() ) );
93
94 foreach my $key ( keys(%$savedMeta) ) {
952170µs2370µs
# spent 196µs (22+174) within Foswiki::Serialise::BEGIN@95 which was called: # once (22µs+174µs) by Foswiki::Meta::BEGIN@120 at line 95
use Scalar::Util qw(blessed reftype);
# spent 196µs making 1 call to Foswiki::Serialise::BEGIN@95 # spent 174µs making 1 call to Exporter::import
96 if ( blessed( $savedMeta->{$key} ) ) {
97
98 #print STDERR "WARNING: skipping $key, its a blessed object\n";
99 next;
100 }
101 else {
102
103#print STDERR "WARNING: using $key - itsa ".(blessed($savedMeta->{$key})||reftype($savedMeta->{$key})||ref($savedMeta->{$key}||'notaref'))."\n";
104 }
105
106 #TODO: next if ( $key is one of the array types... and has no elements..
107
108 $meta->{$key} = $savedMeta->{$key};
109 }
110 if ( defined( $meta->{_topic} ) ) {
111
112 #TODO: exclude attachment meta too..
113 my $raw = $savedMeta->getEmbeddedStoreForm();
114 if ( defined($raw) ) {
115 $meta->{_raw_text} = $raw;
116 }
117 }
118
119 return $meta;
120}
121
12215µs1;
123__END__