File Coverage

blib/lib/ExtUtils/XSBuilder/StructureMap.pm
Criterion Covered Total %
statement 12 111 10.8
branch 0 46 0.0
condition 0 17 0.0
subroutine 4 12 33.3
pod 0 8 0.0
total 16 194 8.2


line stmt bran cond sub pod time code
1             package ExtUtils::XSBuilder::StructureMap;
2              
3 1     1   5 use strict;
  1         3  
  1         34  
4 1     1   5 use warnings FATAL => 'all';
  1         22  
  1         41  
5 1     1   6 use ExtUtils::XSBuilder::MapUtil qw(function_table structure_table);
  1         2  
  1         65  
6 1     1   5 use Data::Dumper ;
  1         2  
  1         1946  
7              
8             our @ISA = qw(ExtUtils::XSBuilder::MapBase);
9              
10             sub new {
11 0     0 0   my $class = shift;
12 0           my $self = bless {wrapxs => shift}, $class;
13 0           $self->{IGNORE_RE} = qr{^$};
14 0           return $self ;
15             }
16              
17             sub generate {
18 0     0 0   my $self = shift;
19 0           my $map = $self->get;
20              
21 0           for my $entry (@{ structure_table($self -> {wrapxs}) }) {
  0            
22 0           my $type = $entry->{type};
23 0           my $elts = $entry->{elts};
24              
25 0 0         next unless @$elts;
26 0 0         next if $type =~ $self->{IGNORE_RE};
27 0           next unless grep {
28 0 0         not exists $map->{$type}->{ $_->{name} }
29             } @$elts;
30              
31 0           print "<$type>\n";
32 0           for my $e (@$elts) {
33 0           print " $e->{name}\n";
34             }
35 0           print "\n\n";
36             }
37             }
38              
39 0     0 0   sub disabled { shift->{disabled} }
40              
41             sub check {
42 0     0 0   my $self = shift;
43 0           my $map = $self->get;
44              
45 0           my @missing;
46 0           my $parsesource = $self -> {wrapxs} -> parsesource_objects ;
47              
48 0           loop:
49 0           for my $entry (@{ structure_table($self -> {wrapxs}) }) {
50 0           my $type = $entry->{type};
51              
52 0           for my $name (map $_->{name}, @{ $entry->{elts} }) {
  0            
53 0 0         next if exists $map->{$type}->{$name};
54 0 0         next if $type =~ $self->{IGNORE_RE};
55 0           push @missing, "$type.$name";
56             }
57 0 0         push @missing, "$type.new" if (!exists $map->{$type}->{'new'}) ;
58 0 0         push @missing, "$type.private" if (!exists $map->{$type}->{'private'}) ;
59             }
60              
61 0 0         return @missing ? \@missing : undef;
62             }
63              
64             sub check_exists {
65 0     0 0   my $self = shift;
66              
67 0           my %structures;
68 0           for my $entry (@{ structure_table($self -> {wrapxs}) }) {
  0            
69 0           $structures{ $entry->{type} } = { map {
70 0           $_->{name}, 1
71 0           } @{ $entry->{elts} } };
72             }
73              
74 0           my @missing;
75              
76 0           while (my($type, $elts) = each %{ $self->{map} }) {
  0            
77 0           for my $name (keys %$elts) {
78 0 0         next if exists $structures{$type}->{$name};
79 0           push @missing, "$type.$name";
80             }
81             }
82              
83 0 0         return @missing ? \@missing : undef;
84             }
85              
86             sub parse {
87 0     0 0   my($self, $fh, $map) = @_;
88              
89 0           my($disabled, $class, $class2);
90 0           my %cur;
91 0           my %malloc;
92 0           my %free;
93              
94 0           while ($fh->readline) {
95 0 0         if (/MALLOC=\s*(.*?)\s*:\s*(.*?)$/) {
96 0           $malloc{$1} = $2 ;
97 0           next;
98             }
99 0 0         if (/FREE=\s*(.*?)\s*:\s*(.*?)$/) {
    0          
    0          
    0          
100 0           $free{$1} = $2 ;
101 0           next;
102             }
103             elsif (m:^(\W?)]+)>:) {
104 0           $map->{$class}{-malloc} = { %malloc } ;
105 0           $map->{$class}{-free} = { %free } ;
106 0           next;
107             }
108             elsif (m:^(\W?)]+)>:) {
109 0           my $args;
110 0           $disabled = $1;
111 0           ($class, $args) = split /\s+/, $2, 2;
112 0 0         if ($class eq 'struct')
113             {
114 0           ($class2, $args) = split /\s+/, $args, 2;
115 0           $class .= ' ' . $class2 ;
116             }
117              
118 0           %cur = ();
119 0 0 0       if ($args and $args =~ /E=/) {
120 0           %cur = $self->parse_keywords($args);
121             }
122              
123 0 0         $self->{MODULES}->{$class} = $cur{MODULE} if $cur{MODULE};
124              
125 0           next;
126             }
127             elsif (s/^(\w+):\s*//) {
128 0           push @{ $self->{$1} }, split /\s+/;
  0            
129 0           next;
130             }
131              
132 0 0 0       if (s/^(\W)\s*// or $disabled) {
133 0           my @parts = split /\s*\|\s*/ ;
134 0           $map->{$class}->{$parts[0]} = undef;
135 0   0       push @{ $self->{disabled}->{ $1 || '!' } }, "$class.$_";
  0            
136             }
137             else {
138 0           my @parts = split /\s*\|\s*/ ;
139 0   0       $map->{$class}->{$parts[0]} = { name => $parts[0],
140             perl_name => $parts[1] || $parts[0],
141             type => $parts[2] } ;
142              
143             }
144             }
145              
146 0 0         if (my $ignore = $self->{IGNORE}) {
147 0           $ignore = join '|', @$ignore;
148 0           $self->{IGNORE_RE} = qr{^($ignore)};
149             }
150             else {
151 0           $self->{IGNORE_RE} = qr{^$};
152             }
153             }
154              
155             sub get {
156 0     0 0   my $self = shift;
157              
158 0   0       $self->{map} ||= $self->parse_map_files;
159             }
160              
161              
162             sub write {
163 0     0 0   my ($self, $fh, $newentries, $prefix) = @_ ;
164              
165 0           my $last = '' ;
166 0           foreach my $type (@$newentries)
167             {
168 0           my ($struct, $elem) = split (/\./, $type) ;
169 0 0 0       $fh -> print ("$prefix\n") if ($last && $last ne $struct) ;
170 0 0         $fh -> print ("$prefix<$struct>\n") if ($last ne $struct) ;
171 0           $last = $struct ;
172 0           $fh -> print ($prefix, ' ', $self -> {wrapxs} -> mapline_elem ($elem), "\n") ;
173             }
174 0 0         $fh -> print ("$prefix\n") if ($last) ;
175             }
176              
177              
178              
179             1;
180             __END__