| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Video::Delay::Func; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Pragmas. | 
| 4 | 4 |  |  | 4 |  | 111975 | use strict; | 
|  | 4 |  |  |  |  | 11 |  | 
|  | 4 |  |  |  |  | 94 |  | 
| 5 | 4 |  |  | 4 |  | 20 | use warnings; | 
|  | 4 |  |  |  |  | 1261 |  | 
|  | 4 |  |  |  |  | 1367 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # Modules. | 
| 8 | 4 |  |  | 4 |  | 2906 | use Class::Utils qw(set_params); | 
|  | 4 |  |  |  |  | 83270 |  | 
|  | 4 |  |  |  |  | 86 |  | 
| 9 | 4 |  |  | 4 |  | 258 | use English qw(-no_match_vars); | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 26 |  | 
| 10 | 4 |  |  | 4 |  | 1930 | use Error::Pure qw(err); | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 1140 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # Version. | 
| 13 |  |  |  |  |  |  | our $VERSION = 0.06; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # Constructor. | 
| 16 |  |  |  |  |  |  | sub new { | 
| 17 | 7 |  |  | 7 | 1 | 7883 | my ($class, @params) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # Create object. | 
| 20 | 7 |  |  |  |  | 15 | my $self = bless {}, $class; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # Math function. | 
| 23 |  |  |  |  |  |  | $self->{'func'} = sub { | 
| 24 | 1 |  |  | 1 |  | 2 | my $t = shift; | 
| 25 | 1 |  |  |  |  | 6 | return 1000 * sin($t); | 
| 26 | 7 |  |  |  |  | 38 | }; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # Counter increment. | 
| 29 | 7 |  |  |  |  | 11 | $self->{'incr'} = 0.1; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | # Process params. | 
| 32 | 7 |  |  |  |  | 28 | set_params($self, @params); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | # Counter. | 
| 35 | 5 |  |  |  |  | 60 | $self->{'counter'} = 0; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | # Check 'func' parameters. | 
| 38 | 5 | 100 | 100 |  |  | 32 | if (ref $self->{'func'} ne '' && ref $self->{'func'} ne 'CODE') { | 
| 39 | 1 |  |  |  |  | 3 | err "Parameter 'func' must be scalar or code."; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # Object. | 
| 43 | 4 |  |  |  |  | 11 | return $self; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # Get delay. | 
| 47 |  |  |  |  |  |  | sub delay { | 
| 48 | 8 |  |  | 8 | 1 | 1748 | my $self = shift; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # Counter. | 
| 51 | 8 |  |  |  |  | 17 | $self->{'counter'} += $self->{'incr'}; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # Function string. | 
| 54 | 8 |  |  |  |  | 8 | my $ret; | 
| 55 | 8 | 100 |  |  |  | 20 | if (ref $self->{'func'} eq '') { | 
| 56 | 4 |  |  |  |  | 5 | my $input = $self->{'func'}; | 
| 57 | 4 |  |  |  |  | 5 | my $c = $self->{'counter'}; | 
| 58 | 4 |  |  |  |  | 12 | $input =~ s/t/$c/g; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | # Eval. | 
| 61 | 4 |  |  |  |  | 142 | $ret = eval $input; | 
| 62 | 4 | 100 |  |  |  | 16 | if ($EVAL_ERROR) { | 
| 63 | 1 |  |  |  |  | 6 | err 'Error in function.', | 
| 64 |  |  |  |  |  |  | 'Error', $EVAL_ERROR; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | # Callback. | 
| 68 |  |  |  |  |  |  | } else { | 
| 69 | 4 |  |  |  |  | 11 | $ret = $self->{'func'}->($self->{'counter'}); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 7 |  |  |  |  | 23 | return $ret; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | 1; | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | __END__ |