| Filename | /home/hejohns/perl5/lib/perl5/Data/Printer.pm |
| Statements | Executed 47 statements in 1.15ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 3.46ms | 11.8ms | Data::Printer::BEGIN@4 |
| 1 | 1 | 1 | 1.46ms | 1.50ms | Data::Printer::BEGIN@6 |
| 1 | 1 | 1 | 13µs | 247µs | Data::Printer::import |
| 1 | 1 | 1 | 8µs | 24µs | Data::Printer::BEGIN@47 |
| 1 | 1 | 1 | 7µs | 8µs | Data::Printer::BEGIN@2 |
| 1 | 1 | 1 | 6µs | 11µs | Data::Printer::BEGIN@39 |
| 1 | 1 | 1 | 6µs | 219µs | Data::Printer::_initialize |
| 1 | 1 | 1 | 5µs | 6µs | Data::Printer::BEGIN@5 |
| 1 | 1 | 1 | 4µs | 14µs | Data::Printer::BEGIN@60 |
| 2 | 2 | 1 | 3µs | 3µs | Data::Printer::_find_option |
| 1 | 1 | 1 | 3µs | 15µs | Data::Printer::BEGIN@3 |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::__ANON__[:47] |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::__ANON__[:69] |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::__ANON__[:73] |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::_fetch_args_with |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::_handle_output |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::_p_without_prototypes |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::np |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::p |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Data::Printer; | ||||
| 2 | 2 | 15µs | 2 | 10µs | # spent 8µs (7+1) within Data::Printer::BEGIN@2 which was called:
# once (7µs+1µs) by main::BEGIN@48 at line 2 # spent 8µs making 1 call to Data::Printer::BEGIN@2
# spent 1µs making 1 call to strict::import |
| 3 | 2 | 12µs | 2 | 27µs | # spent 15µs (3+12) within Data::Printer::BEGIN@3 which was called:
# once (3µs+12µs) by main::BEGIN@48 at line 3 # spent 15µs making 1 call to Data::Printer::BEGIN@3
# spent 12µs making 1 call to warnings::import |
| 4 | 2 | 77µs | 2 | 11.8ms | # spent 11.8ms (3.46+8.38) within Data::Printer::BEGIN@4 which was called:
# once (3.46ms+8.38ms) by main::BEGIN@48 at line 4 # spent 11.8ms making 1 call to Data::Printer::BEGIN@4
# spent 1µs making 1 call to Data::Printer::__ANON__ |
| 5 | 2 | 15µs | 2 | 6µs | # spent 6µs (5+200ns) within Data::Printer::BEGIN@5 which was called:
# once (5µs+200ns) by main::BEGIN@48 at line 5 # spent 6µs making 1 call to Data::Printer::BEGIN@5
# spent 200ns making 1 call to Data::Printer::__ANON__ |
| 6 | 2 | 177µs | 2 | 1.50ms | # spent 1.50ms (1.46+40µs) within Data::Printer::BEGIN@6 which was called:
# once (1.46ms+40µs) by main::BEGIN@48 at line 6 # spent 1.50ms making 1 call to Data::Printer::BEGIN@6
# spent 700ns making 1 call to Data::Printer::__ANON__ |
| 7 | |||||
| 8 | 1 | 200ns | our $VERSION = '1.001000'; | ||
| 9 | 1 | 22µs | $VERSION = eval $VERSION; # spent 2µs executing statements in string eval | ||
| 10 | |||||
| 11 | 1 | 100ns | my $rc_arguments; | ||
| 12 | my %arguments_for; | ||||
| 13 | |||||
| 14 | # spent 247µs (13+234) within Data::Printer::import which was called:
# once (13µs+234µs) by main::BEGIN@48 at line 48 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl | ||||
| 15 | 1 | 300ns | my $class = shift; | ||
| 16 | |||||
| 17 | 1 | 500ns | 1 | 219µs | _initialize(); # spent 219µs making 1 call to Data::Printer::_initialize |
| 18 | |||||
| 19 | 1 | 200ns | my $args; | ||
| 20 | 1 | 300ns | if (@_ > 0) { | ||
| 21 | $args = @_ == 1 ? shift : {@_}; | ||||
| 22 | Data::Printer::Common::_warn( | ||||
| 23 | undef, | ||||
| 24 | 'Data::Printer can receive either a hash or a hash reference' | ||||
| 25 | ) unless ref $args eq 'HASH'; | ||||
| 26 | $args = Data::Printer::Config::_expand_profile($args) | ||||
| 27 | if exists $args->{profile}; | ||||
| 28 | } | ||||
| 29 | |||||
| 30 | # every time you load it, we override the version from *your* caller | ||||
| 31 | 1 | 1µs | 1 | 11µs | my $caller = caller; # spent 11µs making 1 call to Contextual::Return::__ANON__[Contextual/Return.pm:30] |
| 32 | 1 | 600ns | $arguments_for{$caller} = $args; | ||
| 33 | |||||
| 34 | 1 | 800ns | 1 | 2µs | my $use_prototypes = _find_option('use_prototypes', $args, $caller, 1); # spent 2µs making 1 call to Data::Printer::_find_option |
| 35 | 1 | 500ns | my $exported = ($use_prototypes ? \&p : \&_p_without_prototypes); | ||
| 36 | |||||
| 37 | 1 | 400ns | 1 | 1µs | my $imported = _find_option('alias', $args, $caller, 'p'); # spent 1µs making 1 call to Data::Printer::_find_option |
| 38 | |||||
| 39 | 3 | 64µs | 2 | 16µs | # spent 11µs (6+5) within Data::Printer::BEGIN@39 which was called:
# once (6µs+5µs) by main::BEGIN@48 at line 39 # spent 11µs making 1 call to Data::Printer::BEGIN@39
# spent 5µs making 1 call to strict::unimport |
| 40 | 1 | 2µs | *{"$caller\::$imported"} = $exported; | ||
| 41 | 1 | 1µs | *{"$caller\::np"} = \&np; | ||
| 42 | } | ||||
| 43 | } | ||||
| 44 | |||||
| 45 | # spent 219µs (6+213) within Data::Printer::_initialize which was called:
# once (6µs+213µs) by Data::Printer::import at line 17 | ||||
| 46 | # potential race but worst case is we read it twice :) | ||||
| 47 | 4 | 79µs | 2 | 39µs | # spent 24µs (8+15) within Data::Printer::BEGIN@47 which was called:
# once (8µs+15µs) by main::BEGIN@48 at line 47 # spent 24µs making 1 call to Data::Printer::BEGIN@47
# spent 15µs making 1 call to warnings::unimport |
| 48 | |||||
| 49 | 1 | 600ns | 1 | 208µs | my $rc_filename = Data::Printer::Config::_get_first_rc_file_available(); # spent 208µs making 1 call to Data::Printer::Config::_get_first_rc_file_available |
| 50 | 1 | 700ns | 1 | 5µs | $rc_arguments = Data::Printer::Config::load_rc_file($rc_filename); # spent 5µs making 1 call to Data::Printer::Config::load_rc_file |
| 51 | |||||
| 52 | 1 | 2µs | if ( | ||
| 53 | exists $rc_arguments->{'_'}{live_update} | ||||
| 54 | && defined $rc_arguments->{'_'}{live_update} | ||||
| 55 | && $rc_arguments->{'_'}{live_update} =~ /\A\d+\z/ | ||||
| 56 | && $rc_arguments->{'_'}{live_update} > 0) { | ||||
| 57 | my $now = time; | ||||
| 58 | my $last_mod = (stat $rc_filename)[9]; | ||||
| 59 | { | ||||
| 60 | 2 | 666µs | 2 | 25µs | # spent 14µs (4+10) within Data::Printer::BEGIN@60 which was called:
# once (4µs+10µs) by main::BEGIN@48 at line 60 # spent 14µs making 1 call to Data::Printer::BEGIN@60
# spent 10µs making 1 call to warnings::unimport |
| 61 | *_initialize = sub { | ||||
| 62 | if (time - $now > $rc_arguments->{'_'}{live_update}) { | ||||
| 63 | my $new_last_mod = (stat $rc_filename)[9]; | ||||
| 64 | if (defined $new_last_mod && $new_last_mod > $last_mod) { | ||||
| 65 | $now = time; | ||||
| 66 | $last_mod = $new_last_mod; | ||||
| 67 | $rc_arguments = Data::Printer::Config::load_rc_file($rc_filename); | ||||
| 68 | if (!exists $rc_arguments->{'_'}{live_update} || !$rc_arguments->{'_'}{live_update}) { | ||||
| 69 | *_initialize = sub {}; | ||||
| 70 | } | ||||
| 71 | } | ||||
| 72 | } | ||||
| 73 | }; | ||||
| 74 | } | ||||
| 75 | } | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | sub np (\[@$%&];%) { | ||||
| 79 | my (undef, %properties) = @_; | ||||
| 80 | |||||
| 81 | _initialize(); | ||||
| 82 | |||||
| 83 | my $caller = caller; | ||||
| 84 | my $args_to_use = _fetch_args_with($caller, \%properties); | ||||
| 85 | return '' if $args_to_use->{quiet}; | ||||
| 86 | my $printer = Data::Printer::Object->new($args_to_use); | ||||
| 87 | |||||
| 88 | # force color level 0 on 'auto' colors: | ||||
| 89 | if ($printer->colored eq 'auto') { | ||||
| 90 | $printer->{_output_color_level} = 0; | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | my $ref = ref $_[0]; | ||||
| 94 | if ($ref eq 'ARRAY' || $ref eq 'HASH' || ($ref eq 'REF' && ref ${$_[0]} eq 'REF')) { | ||||
| 95 | $printer->{_refcount_base}++; | ||||
| 96 | } | ||||
| 97 | my $output = $printer->parse($_[0]); | ||||
| 98 | if ($printer->caller_message_position eq 'after') { | ||||
| 99 | $output .= $printer->_write_label; | ||||
| 100 | } | ||||
| 101 | else { | ||||
| 102 | $output = $printer->_write_label . $output; | ||||
| 103 | } | ||||
| 104 | return $output; | ||||
| 105 | } | ||||
| 106 | |||||
| 107 | |||||
| 108 | sub p (\[@$%&];%) { | ||||
| 109 | my (undef, %properties) = @_; | ||||
| 110 | |||||
| 111 | _initialize(); | ||||
| 112 | |||||
| 113 | my $caller = caller; | ||||
| 114 | my $args_to_use = _fetch_args_with($caller, \%properties); | ||||
| 115 | return if $args_to_use->{quiet}; | ||||
| 116 | my $printer = Data::Printer::Object->new($args_to_use); | ||||
| 117 | my $want_value = defined wantarray; | ||||
| 118 | if ($printer->colored eq 'auto' && $printer->return_value eq 'dump' && $want_value) { | ||||
| 119 | $printer->{_output_color_level} = 0; | ||||
| 120 | } | ||||
| 121 | |||||
| 122 | my $ref = ref $_[0]; | ||||
| 123 | if ($ref eq 'ARRAY' || $ref eq 'HASH' || ($ref eq 'REF' && ref ${$_[0]} eq 'REF')) { | ||||
| 124 | $printer->{_refcount_base}++; | ||||
| 125 | } | ||||
| 126 | my $output = $printer->parse($_[0]); | ||||
| 127 | if ($printer->caller_message_position eq 'after') { | ||||
| 128 | $output .= $printer->_write_label; | ||||
| 129 | } | ||||
| 130 | else { | ||||
| 131 | $output = $printer->_write_label . $output; | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | return _handle_output($printer, $output, $want_value, $_[0]); | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | # This is a p() clone without prototypes. Just like regular Data::Dumper, | ||||
| 138 | # this version expects a reference as its first argument. We make a single | ||||
| 139 | # exception for when we only get one argument, in which case we ref it | ||||
| 140 | # for the user and keep going. | ||||
| 141 | sub _p_without_prototypes { | ||||
| 142 | my (undef, %properties) = @_; | ||||
| 143 | |||||
| 144 | my $item; | ||||
| 145 | if (!ref $_[0] && @_ == 1) { | ||||
| 146 | my $item_value = $_[0]; | ||||
| 147 | $item = \$item_value; | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | _initialize(); | ||||
| 151 | |||||
| 152 | my $caller = caller; | ||||
| 153 | my $args_to_use = _fetch_args_with($caller, \%properties); | ||||
| 154 | return if $args_to_use->{quiet}; | ||||
| 155 | my $printer = Data::Printer::Object->new($args_to_use); | ||||
| 156 | |||||
| 157 | my $want_value = defined wantarray; | ||||
| 158 | if ($printer->colored eq 'auto' && $printer->return_value eq 'dump' && $want_value) { | ||||
| 159 | $printer->{_output_color_level} = 0; | ||||
| 160 | } | ||||
| 161 | |||||
| 162 | my $ref = ref( defined $item ? $item : $_[0] ); | ||||
| 163 | if ($ref eq 'ARRAY' || $ref eq 'HASH' || ($ref eq 'REF' | ||||
| 164 | && ref(defined $item ? $item : ${$_[0]}) eq 'REF')) { | ||||
| 165 | $printer->{_refcount_base}++; | ||||
| 166 | } | ||||
| 167 | my $output = $printer->parse((defined $item ? $item : $_[0])); | ||||
| 168 | if ($printer->caller_message_position eq 'after') { | ||||
| 169 | $output .= $printer->_write_label; | ||||
| 170 | } | ||||
| 171 | else { | ||||
| 172 | $output = $printer->_write_label . $output; | ||||
| 173 | } | ||||
| 174 | |||||
| 175 | return _handle_output($printer, $output, $want_value, $_[0]); | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | |||||
| 179 | sub _handle_output { | ||||
| 180 | my ($printer, $output, $wantarray, $data) = @_; | ||||
| 181 | |||||
| 182 | if ($printer->return_value eq 'pass') { | ||||
| 183 | print { $printer->{output_handle} } $output . "\n"; | ||||
| 184 | require Scalar::Util; | ||||
| 185 | my $ref = Scalar::Util::blessed($data); | ||||
| 186 | return $data if defined $ref; | ||||
| 187 | $ref = Scalar::Util::reftype($data); | ||||
| 188 | if (!$ref) { | ||||
| 189 | return $data; | ||||
| 190 | } | ||||
| 191 | elsif ($ref eq 'ARRAY') { | ||||
| 192 | return @$data; | ||||
| 193 | } | ||||
| 194 | elsif ($ref eq 'HASH') { | ||||
| 195 | return %$data; | ||||
| 196 | } | ||||
| 197 | elsif ( grep { $ref eq $_ } qw(REF SCALAR VSTRING) ) { | ||||
| 198 | return $$data; | ||||
| 199 | } | ||||
| 200 | else { | ||||
| 201 | return $data; | ||||
| 202 | } | ||||
| 203 | } | ||||
| 204 | elsif ($printer->return_value eq 'void' || !$wantarray) { | ||||
| 205 | print { $printer->{output_handle} } $output . "\n"; | ||||
| 206 | return; | ||||
| 207 | } | ||||
| 208 | else { | ||||
| 209 | return $output; | ||||
| 210 | } | ||||
| 211 | } | ||||
| 212 | |||||
| 213 | sub _fetch_args_with { | ||||
| 214 | my ($caller, $run_properties) = @_; | ||||
| 215 | |||||
| 216 | my $args_to_use = {}; | ||||
| 217 | if (keys %$rc_arguments) { | ||||
| 218 | $args_to_use = Data::Printer::Config::_merge_options( | ||||
| 219 | $args_to_use, $rc_arguments->{'_'} | ||||
| 220 | ); | ||||
| 221 | if (exists $rc_arguments->{$caller}) { | ||||
| 222 | $args_to_use = Data::Printer::Config::_merge_options( | ||||
| 223 | $args_to_use, $rc_arguments->{$caller} | ||||
| 224 | ); | ||||
| 225 | } | ||||
| 226 | } | ||||
| 227 | if ($arguments_for{$caller}) { | ||||
| 228 | $args_to_use = Data::Printer::Config::_merge_options( | ||||
| 229 | $args_to_use, $arguments_for{$caller} | ||||
| 230 | ); | ||||
| 231 | } | ||||
| 232 | if (keys %$run_properties) { | ||||
| 233 | $run_properties = Data::Printer::Config::_expand_profile($run_properties) | ||||
| 234 | if exists $run_properties->{profile}; | ||||
| 235 | $args_to_use = Data::Printer::Config::_merge_options( | ||||
| 236 | $args_to_use, $run_properties | ||||
| 237 | ); | ||||
| 238 | } | ||||
| 239 | return $args_to_use; | ||||
| 240 | } | ||||
| 241 | |||||
| 242 | |||||
| 243 | sub _find_option { | ||||
| 244 | 2 | 800ns | my ($key, $args, $caller, $default) = @_; | ||
| 245 | |||||
| 246 | 2 | 200ns | my $value; | ||
| 247 | 2 | 1µs | if (exists $args->{$key}) { | ||
| 248 | $value = $args->{$key}; | ||||
| 249 | } | ||||
| 250 | elsif ( | ||||
| 251 | exists $rc_arguments->{$caller} | ||||
| 252 | && exists $rc_arguments->{$caller}{$key} | ||||
| 253 | ) { | ||||
| 254 | $value = $rc_arguments->{$caller}{$key}; | ||||
| 255 | } | ||||
| 256 | elsif (exists $rc_arguments->{'_'}{$key}) { | ||||
| 257 | $value = $rc_arguments->{'_'}{$key}; | ||||
| 258 | } | ||||
| 259 | else { | ||||
| 260 | 2 | 300ns | $value = $default; | ||
| 261 | } | ||||
| 262 | 2 | 3µs | return $value; | ||
| 263 | } | ||||
| 264 | |||||
| 265 | |||||
| 266 | 1 | 3µs | 'Marielle, presente.'; | ||
| 267 | __END__ |