| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Log/Log4perl/Filter/Boolean.pm |
| Statements | Executed 22 statements in 501µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 35µs | 37µs | Log::Log4perl::Filter::Boolean::BEGIN@7 |
| 1 | 1 | 1 | 24µs | 24µs | Log::Log4perl::Filter::Boolean::BEGIN@5 |
| 1 | 1 | 1 | 11µs | 85µs | Log::Log4perl::Filter::Boolean::BEGIN@15 |
| 1 | 1 | 1 | 8µs | 51µs | Log::Log4perl::Filter::Boolean::BEGIN@10 |
| 1 | 1 | 1 | 6µs | 34µs | Log::Log4perl::Filter::Boolean::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 15µs | Log::Log4perl::Filter::Boolean::BEGIN@8 |
| 1 | 1 | 1 | 4µs | 4µs | Log::Log4perl::Filter::Boolean::BEGIN@11 |
| 0 | 0 | 0 | 0s | 0s | Log::Log4perl::Filter::Boolean::compile_logic |
| 0 | 0 | 0 | 0s | 0s | Log::Log4perl::Filter::Boolean::eval_logic |
| 0 | 0 | 0 | 0s | 0s | Log::Log4perl::Filter::Boolean::new |
| 0 | 0 | 0 | 0s | 0s | Log::Log4perl::Filter::Boolean::ok |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ################################################## | ||||
| 2 | package Log::Log4perl::Filter::Boolean; | ||||
| 3 | ################################################## | ||||
| 4 | |||||
| 5 | 3 | 33µs | 1 | 24µs | # spent 24µs within Log::Log4perl::Filter::Boolean::BEGIN@5 which was called:
# once (24µs+0s) by Log::Log4perl::Config::BEGIN@13 at line 5 # spent 24µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@5 |
| 6 | |||||
| 7 | 3 | 18µs | 2 | 39µs | # spent 37µs (35+2) within Log::Log4perl::Filter::Boolean::BEGIN@7 which was called:
# once (35µs+2µs) by Log::Log4perl::Config::BEGIN@13 at line 7 # spent 37µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@7
# spent 2µs making 1 call to strict::import |
| 8 | 3 | 34µs | 2 | 23µs | # spent 15µs (6+8) within Log::Log4perl::Filter::Boolean::BEGIN@8 which was called:
# once (6µs+8µs) by Log::Log4perl::Config::BEGIN@13 at line 8 # spent 15µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@8
# spent 8µs making 1 call to warnings::import |
| 9 | |||||
| 10 | 3 | 18µs | 2 | 93µs | # spent 51µs (8+43) within Log::Log4perl::Filter::Boolean::BEGIN@10 which was called:
# once (8µs+43µs) by Log::Log4perl::Config::BEGIN@13 at line 10 # spent 51µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@10
# spent 43µs making 1 call to Log::Log4perl::Level::import |
| 11 | 3 | 18µs | 1 | 4µs | # spent 4µs within Log::Log4perl::Filter::Boolean::BEGIN@11 which was called:
# once (4µs+0s) by Log::Log4perl::Config::BEGIN@13 at line 11 # spent 4µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@11 |
| 12 | |||||
| 13 | 3 | 26µs | 2 | 62µs | # spent 34µs (6+28) within Log::Log4perl::Filter::Boolean::BEGIN@13 which was called:
# once (6µs+28µs) by Log::Log4perl::Config::BEGIN@13 at line 13 # spent 34µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@13
# spent 28µs making 1 call to constant::import |
| 14 | |||||
| 15 | 3 | 352µs | 2 | 85µs | # spent 85µs (11+74) within Log::Log4perl::Filter::Boolean::BEGIN@15 which was called:
# once (11µs+74µs) by Log::Log4perl::Config::BEGIN@13 at line 15 # spent 85µs making 1 call to Log::Log4perl::Filter::Boolean::BEGIN@15
# spent 74µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 74µs |
| 16 | |||||
| 17 | ################################################## | ||||
| 18 | sub new { | ||||
| 19 | ################################################## | ||||
| 20 | my ($class, %options) = @_; | ||||
| 21 | |||||
| 22 | my $self = { params => {}, | ||||
| 23 | %options, | ||||
| 24 | }; | ||||
| 25 | |||||
| 26 | bless $self, $class; | ||||
| 27 | |||||
| 28 | print "Compiling '$options{logic}'\n" if _INTERNAL_DEBUG; | ||||
| 29 | |||||
| 30 | # Set up meta-decider for later | ||||
| 31 | $self->compile_logic($options{logic}); | ||||
| 32 | |||||
| 33 | return $self; | ||||
| 34 | } | ||||
| 35 | |||||
| 36 | ################################################## | ||||
| 37 | sub ok { | ||||
| 38 | ################################################## | ||||
| 39 | my ($self, %p) = @_; | ||||
| 40 | |||||
| 41 | return $self->eval_logic(\%p); | ||||
| 42 | } | ||||
| 43 | |||||
| 44 | ################################################## | ||||
| 45 | sub compile_logic { | ||||
| 46 | ################################################## | ||||
| 47 | my ($self, $logic) = @_; | ||||
| 48 | |||||
| 49 | # Extract Filter placeholders in logic as defined | ||||
| 50 | # in configuration file. | ||||
| 51 | while($logic =~ /([\w_-]+)/g) { | ||||
| 52 | # Get the corresponding filter object | ||||
| 53 | my $filter = Log::Log4perl::Filter::by_name($1); | ||||
| 54 | die "Filter $filter required by Boolean filter, but not defined" | ||||
| 55 | unless $filter; | ||||
| 56 | |||||
| 57 | $self->{params}->{$1} = $filter; | ||||
| 58 | } | ||||
| 59 | |||||
| 60 | # Fabricate a parameter list: A1/A2/A3 => $A1, $A2, $A3 | ||||
| 61 | my $plist = join ', ', map { '$' . $_ } keys %{$self->{params}}; | ||||
| 62 | |||||
| 63 | # Replace all the (dollar-less) placeholders in the code | ||||
| 64 | # by scalars (basically just put dollars in front of them) | ||||
| 65 | $logic =~ s/([\w_-]+)/\$$1/g; | ||||
| 66 | |||||
| 67 | # Set up the meta decider, which transforms the config file | ||||
| 68 | # logic into compiled perl code | ||||
| 69 | my $func = <<EOT; | ||||
| 70 | sub { | ||||
| 71 | my($plist) = \@_; | ||||
| 72 | $logic; | ||||
| 73 | } | ||||
| 74 | EOT | ||||
| 75 | |||||
| 76 | print "func=$func\n" if _INTERNAL_DEBUG; | ||||
| 77 | |||||
| 78 | my $eval_func = eval $func; | ||||
| 79 | |||||
| 80 | if(! $eval_func) { | ||||
| 81 | die "Syntax error in Boolean filter logic: $eval_func"; | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | $self->{eval_func} = $eval_func; | ||||
| 85 | } | ||||
| 86 | |||||
| 87 | ################################################## | ||||
| 88 | sub eval_logic { | ||||
| 89 | ################################################## | ||||
| 90 | my($self, $p) = @_; | ||||
| 91 | |||||
| 92 | my @plist = (); | ||||
| 93 | |||||
| 94 | # Eval the results of all filters referenced | ||||
| 95 | # in the code (although the order of keys is | ||||
| 96 | # not predictable, it is consistent :) | ||||
| 97 | for my $param (keys %{$self->{params}}) { | ||||
| 98 | # Call ok() and map the result to 1 or 0 | ||||
| 99 | print "Calling filter $param\n" if _INTERNAL_DEBUG; | ||||
| 100 | push @plist, ($self->{params}->{$param}->ok(%$p) ? 1 : 0); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | # Now pipe the parameters into the canned function, | ||||
| 104 | # have it evaluate the logic and return the final | ||||
| 105 | # decision | ||||
| 106 | print "Passing in (", join(', ', @plist), ")\n" if _INTERNAL_DEBUG; | ||||
| 107 | return $self->{eval_func}->(@plist); | ||||
| 108 | } | ||||
| 109 | |||||
| 110 | 1 | 2µs | 1; | ||
| 111 | |||||
| 112 | __END__ |