line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2731
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
3
|
use FFI::C; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
274
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package ColorValue { |
6
|
|
|
|
|
|
|
FFI::C->struct([ |
7
|
|
|
|
|
|
|
red => 'uint8', |
8
|
|
|
|
|
|
|
green => 'uint8', |
9
|
|
|
|
|
|
|
blue => 'uint8', |
10
|
|
|
|
|
|
|
]); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package NamedColor { |
14
|
|
|
|
|
|
|
FFI::C->struct([ |
15
|
|
|
|
|
|
|
name => 'string(22)', |
16
|
|
|
|
|
|
|
value => 'color_value_t', |
17
|
|
|
|
|
|
|
]); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package ArrayNamedColor { |
21
|
|
|
|
|
|
|
FFI::C->array(['named_color_t' => 4]); |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $array = ArrayNamedColor->new([ |
25
|
|
|
|
|
|
|
{ name => "red", value => { red => 255 } }, |
26
|
|
|
|
|
|
|
{ name => "green", value => { green => 255 } }, |
27
|
|
|
|
|
|
|
{ name => "blue", value => { blue => 255 } }, |
28
|
|
|
|
|
|
|
{ name => "purple", value => { red => 255, |
29
|
|
|
|
|
|
|
blue => 255 } }, |
30
|
|
|
|
|
|
|
]); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# dim each color by 1/2 |
33
|
|
|
|
|
|
|
foreach my $color (@$array) |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
$color->value->red ( $color->value->red / 2 ); |
36
|
|
|
|
|
|
|
$color->value->green( $color->value->green / 2 ); |
37
|
|
|
|
|
|
|
$color->value->blue ( $color->value->blue / 2 ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# print out the colors |
41
|
|
|
|
|
|
|
foreach my $color (@$array) |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
printf "%s [%02x %02x %02x]\n", |
44
|
|
|
|
|
|
|
$color->name, |
45
|
|
|
|
|
|
|
$color->value->red, |
46
|
|
|
|
|
|
|
$color->value->green, |
47
|
|
|
|
|
|
|
$color->value->blue; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package AnyInt { |
51
|
|
|
|
|
|
|
FFI::C->union([ |
52
|
|
|
|
|
|
|
u8 => 'uint8', |
53
|
|
|
|
|
|
|
u16 => 'uint16', |
54
|
|
|
|
|
|
|
u32 => 'uint32', |
55
|
|
|
|
|
|
|
u64 => 'uint64', |
56
|
|
|
|
|
|
|
]); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $int = AnyInt->new({ u8 => 42 }); |
60
|
|
|
|
|
|
|
print $int->u32; |
61
|
|
|
|
|
|
|
|