Delay/Func.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 61 / 61 CC 5 SCAR 6.9
CC
5
Cov
100%
new
3.0
delay
3.0
BEGIN
1.0
CRAP 2.0
« Delay/Array.pm ↑ Summary Delay.pm »
1 package Video::Delay::Func;
2  
3 # Pragmas.
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Modules.
8 4 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Version.
13 4 our $VERSION = 0.06;
14  
15 # Constructor.
16 sub new {
17 7 ▶ my ($class, @params) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
18  
19 # Create object.
20 7 my $self = bless {}, $class;
21  
22 # Math function.
23 $self->{'func'} = sub {
24 1 ▶ my $t = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
25 1 return 1000 * sin($t);
26 7 };
27  
28 # Counter increment.
29 7 $self->{'incr'} = 0.1;
30  
31 # Process params.
32 7 set_params($self, @params);
33  
34 # Counter.
35 5 $self->{'counter'} = 0;
36  
37 # Check 'func' parameters.
38 5 ▶ if (ref $self->{'func'} ne '' && ref $self->{'func'} ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"func"} ne "" and ref $self->{"func"} ne "CODE") 1 4 5
Condition100%3/3
ref $self->{"func"} ne "" and ref $self->{"func"} ne "CODE"
!ll&&!rl&&r
221
MC/DC100%2/2
ref $self->{"func"} ne "" and ref $self->{"func"} ne "CODE"
ref $self->{"func"} ne "" ref $self->{"func"} ne "CODE"
Truth table100%3/3
A and B
A= ref $self->{"func"} ne ""B= ref $self->{"func"} ne "CODE"
ABresult
0X0
100
111
39 1 err "Parameter 'func' must be scalar or code.";
40 }
41  
42 # Object.
43 4 return $self;
44 }
45  
46 # Get delay.
47 sub delay {
48 8 ▶ my $self = shift;
Subroutine delay: called CC=3 SCAR=11.0
Pod documented
49  
50 # Counter.
51 8 $self->{'counter'} += $self->{'incr'};
52  
53 # Function string.
54 8 my $ret;
55 8 ▶ if (ref $self->{'func'} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'func'} eq '') { } 4 4 8
56 4 my $input = $self->{'func'};
57 4 my $c = $self->{'counter'};
58 4 $input =~ s/t/$c/g;
59  
60 # Eval.
61 4 $ret = eval $input;
62 4 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Video::Delay::Func::EVAL_ERROR) 1 3 4
63 1 err 'Error in function.',
64 'Error', $EVAL_ERROR;
65 }
66  
67 # Callback.
68 } else {
69 4 $ret = $self->{'func'}->($self->{'counter'});
70 }
71  
72 7 return $ret;
73 }
74  
75 4 1;
76  
77 __END__
« Delay/Array.pm ↑ Summary Delay.pm »