Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/CHI.pm |
Statements | Executed 32 statements in 793µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.51ms | 3.52ms | BEGIN@8 | CHI::
1 | 1 | 1 | 676µs | 30.6ms | BEGIN@5 | CHI::
1 | 1 | 1 | 307µs | 693µs | BEGIN@6 | CHI::
1 | 1 | 1 | 12µs | 12µs | BEGIN@3 | CHI::
1 | 1 | 1 | 6µs | 38µs | BEGIN@4 | CHI::
1 | 1 | 1 | 6µs | 11µs | config | CHI::
1 | 1 | 1 | 6µs | 7µs | BEGIN@9 | CHI::
1 | 1 | 1 | 5µs | 20µs | BEGIN@7 | CHI::
1 | 1 | 1 | 5µs | 8µs | BEGIN@10 | CHI::
1 | 1 | 1 | 5µs | 12µs | BEGIN@34 | CHI::
1 | 1 | 1 | 5µs | 11µs | BEGIN@35 | CHI::
1 | 1 | 1 | 5µs | 16µs | BEGIN@39 | CHI::
1 | 1 | 1 | 4µs | 4µs | _set_config | CHI::
1 | 1 | 1 | 400ns | 400ns | __ANON__[:36] | CHI::
0 | 0 | 0 | 0s | 0s | clear_memoized_cache_objects | CHI::
0 | 0 | 0 | 0s | 0s | logger | CHI::
0 | 0 | 0 | 0s | 0s | memoized_cache_objects | CHI::
0 | 0 | 0 | 0s | 0s | new | CHI::
0 | 0 | 0 | 0s | 0s | stats | CHI::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package CHI; | ||||
2 | 1 | 400ns | $CHI::VERSION = '0.60'; | ||
3 | 2 | 29µs | 1 | 12µs | # spent 12µs within CHI::BEGIN@3 which was called:
# once (12µs+0s) by BenchmarkAnything::Storage::Backend::SQL::new at line 3 # spent 12µs making 1 call to CHI::BEGIN@3 |
4 | 2 | 22µs | 2 | 69µs | # spent 38µs (6+31) within CHI::BEGIN@4 which was called:
# once (6µs+31µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 4 # spent 38µs making 1 call to CHI::BEGIN@4
# spent 31µs making 1 call to Exporter::import |
5 | 2 | 79µs | 1 | 30.6ms | # spent 30.6ms (676µs+29.9) within CHI::BEGIN@5 which was called:
# once (676µs+29.9ms) by BenchmarkAnything::Storage::Backend::SQL::new at line 5 # spent 30.6ms making 1 call to CHI::BEGIN@5 |
6 | 2 | 67µs | 2 | 765µs | # spent 693µs (307+386) within CHI::BEGIN@6 which was called:
# once (307µs+386µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 6 # spent 693µs making 1 call to CHI::BEGIN@6
# spent 73µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
7 | 2 | 16µs | 2 | 35µs | # spent 20µs (5+15) within CHI::BEGIN@7 which was called:
# once (5µs+15µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 7 # spent 20µs making 1 call to CHI::BEGIN@7
# spent 15µs making 1 call to Module::Runtime::import |
8 | 2 | 62µs | 1 | 3.52ms | # spent 3.52ms (1.51+2.01) within CHI::BEGIN@8 which was called:
# once (1.51ms+2.01ms) by BenchmarkAnything::Storage::Backend::SQL::new at line 8 # spent 3.52ms making 1 call to CHI::BEGIN@8 |
9 | 2 | 16µs | 2 | 8µs | # spent 7µs (6+1) within CHI::BEGIN@9 which was called:
# once (6µs+1µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 9 # spent 7µs making 1 call to CHI::BEGIN@9
# spent 1µs making 1 call to strict::import |
10 | 2 | 78µs | 2 | 11µs | # spent 8µs (5+3) within CHI::BEGIN@10 which was called:
# once (5µs+3µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 10 # spent 8µs making 1 call to CHI::BEGIN@10
# spent 3µs making 1 call to warnings::import |
11 | |||||
12 | 1 | 200ns | my ( %final_class_seen, %memoized_cache_objects, %stats ); | ||
13 | my %valid_config_keys = | ||||
14 | 1 | 3µs | map { ( $_, 1 ) } qw(defaults memoize_cache_objects namespace storage); | ||
15 | |||||
16 | sub logger { | ||||
17 | warn | ||||
18 | "CHI now uses Log::Any for logging - see Log::Any documentation for details"; | ||||
19 | } | ||||
20 | |||||
21 | # spent 11µs (6+5) within CHI::config which was called:
# once (6µs+5µs) by CHI::BEGIN@39 at line 39 | ||||
22 | 1 | 300ns | my $class = shift; | ||
23 | 1 | 1µs | 1 | 4µs | $class->_set_config(@_) if @_; # spent 4µs making 1 call to CHI::_set_config |
24 | 1 | 2µs | 1 | 400ns | return $class->_get_config(); # spent 400ns making 1 call to CHI::__ANON__[CHI.pm:36] |
25 | } | ||||
26 | |||||
27 | # spent 4µs within CHI::_set_config which was called:
# once (4µs+0s) by CHI::config at line 23 | ||||
28 | 1 | 400ns | my ( $class, $config ) = @_; | ||
29 | 1 | 900ns | if ( my @bad_keys = grep { !$valid_config_keys{$_} } keys(%$config) ) { | ||
30 | croak "unknown keys in config hash: " . join( ", ", @bad_keys ); | ||||
31 | } | ||||
32 | |||||
33 | # set class specific configuration | ||||
34 | 2 | 14µs | 2 | 19µs | # spent 12µs (5+7) within CHI::BEGIN@34 which was called:
# once (5µs+7µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 34 # spent 12µs making 1 call to CHI::BEGIN@34
# spent 7µs making 1 call to strict::unimport |
35 | 2 | 46µs | 2 | 17µs | # spent 11µs (5+6) within CHI::BEGIN@35 which was called:
# once (5µs+6µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 35 # spent 11µs making 1 call to CHI::BEGIN@35
# spent 6µs making 1 call to warnings::unimport |
36 | 2 | 7µs | # spent 400ns within CHI::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/CHI.pm:36] which was called:
# once (400ns+0s) by CHI::config at line 24 | ||
37 | } | ||||
38 | |||||
39 | 1 | 344µs | 2 | 27µs | # spent 16µs (5+11) within CHI::BEGIN@39 which was called:
# once (5µs+11µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 39 # spent 16µs making 1 call to CHI::BEGIN@39
# spent 11µs making 1 call to CHI::config |
40 | |||||
41 | sub memoized_cache_objects { | ||||
42 | my ($class) = @_; | ||||
43 | |||||
44 | # Each CHI root class gets its hash of memoized objects | ||||
45 | # | ||||
46 | $memoized_cache_objects{$class} ||= {}; | ||||
47 | return $memoized_cache_objects{$class}; | ||||
48 | } | ||||
49 | |||||
50 | sub clear_memoized_cache_objects { | ||||
51 | my ($class) = @_; | ||||
52 | |||||
53 | $memoized_cache_objects{$class} = {}; | ||||
54 | } | ||||
55 | |||||
56 | sub stats { | ||||
57 | my ($class) = @_; | ||||
58 | |||||
59 | # Each CHI root class gets its own stats object | ||||
60 | # | ||||
61 | $stats{$class} ||= CHI::Stats->new( chi_root_class => $class ); | ||||
62 | return $stats{$class}; | ||||
63 | } | ||||
64 | |||||
65 | sub new { | ||||
66 | my ( $chi_root_class, %params ) = @_; | ||||
67 | |||||
68 | my $config = $chi_root_class->config; | ||||
69 | |||||
70 | # Cache object memoization: See if cache object with these parameters | ||||
71 | # has already been created, and return it if so. Only for parameters | ||||
72 | # with 0 or 1 keys. | ||||
73 | # | ||||
74 | my ( $cache_object_key, $cache_objects ); | ||||
75 | if ( $config->{memoize_cache_objects} && keys(%params) <= 1 ) { | ||||
76 | $cache_object_key = join chr(28), %params; | ||||
77 | $cache_objects = $chi_root_class->memoized_cache_objects; | ||||
78 | if ( my $cache_object = $cache_objects->{$cache_object_key} ) { | ||||
79 | return $cache_object; | ||||
80 | } | ||||
81 | } | ||||
82 | |||||
83 | # Gather defaults | ||||
84 | # | ||||
85 | my $core_defaults = $config->{defaults} || {}; | ||||
86 | my $namespace_defaults = | ||||
87 | $config->{namespace}->{ $params{namespace} || 'Default' } || {}; | ||||
88 | my $storage = | ||||
89 | $params{storage} | ||||
90 | || $namespace_defaults->{storage} | ||||
91 | || $core_defaults->{storage}; | ||||
92 | my $storage_defaults = {}; | ||||
93 | if ( defined($storage) ) { | ||||
94 | $storage_defaults = $config->{storage}->{$storage} | ||||
95 | or croak "no config for storage type '$storage'"; | ||||
96 | } | ||||
97 | |||||
98 | # Combine passed params with defaults | ||||
99 | # | ||||
100 | %params = | ||||
101 | ( %$core_defaults, %$storage_defaults, %$namespace_defaults, %params ); | ||||
102 | |||||
103 | # Get driver class from driver or driver_class parameters | ||||
104 | # | ||||
105 | my $driver_class; | ||||
106 | if ( my $driver = delete( $params{driver} ) ) { | ||||
107 | ($driver_class) = | ||||
108 | String::RewritePrefix->rewrite( { '' => 'CHI::Driver::', '+' => '' }, | ||||
109 | $driver ); | ||||
110 | } | ||||
111 | else { | ||||
112 | $driver_class = delete( $params{driver_class} ); | ||||
113 | } | ||||
114 | croak "missing required param 'driver' or 'driver_class'" | ||||
115 | unless defined $driver_class; | ||||
116 | |||||
117 | # Load driver class if it hasn't been loaded or defined in-line already | ||||
118 | # | ||||
119 | unless ( $driver_class->can('fetch') ) { | ||||
120 | require_module($driver_class); | ||||
121 | } | ||||
122 | |||||
123 | # Select roles depending on presence of certain arguments. Everyone gets | ||||
124 | # the Universal role. Accept both 'roles' and 'traits' for backwards | ||||
125 | # compatibility. Add CHI::Driver::Role:: unless prefixed with '+'. | ||||
126 | # | ||||
127 | my @roles = ('Universal'); | ||||
128 | foreach my $param_name (qw(roles traits)) { | ||||
129 | if ( exists( $params{$param_name} ) ) { | ||||
130 | push( @roles, @{ delete( $params{$param_name} ) } ); | ||||
131 | } | ||||
132 | } | ||||
133 | if ( exists( $params{max_size} ) || exists( $params{is_size_aware} ) ) { | ||||
134 | push( @roles, 'IsSizeAware' ); | ||||
135 | } | ||||
136 | if ( exists( $params{l1_cache} ) || exists( $params{mirror_cache} ) ) { | ||||
137 | push( @roles, 'HasSubcaches' ); | ||||
138 | } | ||||
139 | if ( $params{is_subcache} ) { | ||||
140 | push( @roles, 'IsSubcache' ); | ||||
141 | } | ||||
142 | @roles = String::RewritePrefix->rewrite( | ||||
143 | { '' => 'CHI::Driver::Role::', '+' => '' }, @roles ); | ||||
144 | |||||
145 | # Select a final class based on the driver class and roles, creating it | ||||
146 | # if necessary - adapted from MooseX::Traits | ||||
147 | # | ||||
148 | my $final_class = | ||||
149 | Moo::Role->create_class_with_roles( $driver_class, @roles ); | ||||
150 | |||||
151 | my $cache_object = $final_class->new( | ||||
152 | chi_root_class => $chi_root_class, | ||||
153 | driver_class => $driver_class, | ||||
154 | %params | ||||
155 | ); | ||||
156 | |||||
157 | # Memoize if appropriate | ||||
158 | # | ||||
159 | if ($cache_object_key) { | ||||
160 | $cache_objects->{$cache_object_key} = $cache_object; | ||||
161 | } | ||||
162 | |||||
163 | return $cache_object; | ||||
164 | } | ||||
165 | |||||
166 | 1 | 4µs | 1; | ||
167 | |||||
168 | __END__ |