File: CallbackMap.pm

package info (click to toggle)
libextutils-xsbuilder-perl 0.28-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 360 kB
  • ctags: 281
  • sloc: perl: 2,836; makefile: 11
file content (97 lines) | stat: -rwxr-xr-x 2,318 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package ExtUtils::XSBuilder::CallbackMap;

use strict;
use warnings FATAL => 'all';
use ExtUtils::XSBuilder::MapUtil qw(callback_table);

our @ISA = qw(ExtUtils::XSBuilder::FunctionMap);

# ============================================================================

#look for callbacks that do not exist in *.map
sub check {
    my $self = shift;
    my $map = $self->get;

    my @missing;
    my $parsesource = $self -> {wrapxs} -> parsesource_objects ;

    loop:
    for my $name (map $_->{name}, @{ callback_table($self -> {wrapxs}) }) {
        next if exists $map->{$name};
        push @missing, $name ;
    }

    return @missing ? \@missing : undef;
}

# ============================================================================

#look for callbacks in *.map that do not exist

sub check_exists {
    my $self = shift;

    my %callbacks = map { $_->{name}, 1 } @{ callback_table($self -> {wrapxs}) };
    my @missing = ();

    #print Data::Dumper -> Dump ([\%callbacks, $self->{map}]) ;

    for my $name (keys %{ $self->{map} }) {
        next if $callbacks{$name};
        push @missing, $name ;
    }

    return @missing ? \@missing : undef;
}


# ============================================================================

sub parse {
    my($self, $fh, $map) = @_;
    my %cur;
    my $disabled = 0;

    while ($fh->readline) {
        my($type, $argspec) = split /\s*\|\s*/;

        my $entry = $map->{$type} = {
           name        => $type,
           argspec     => $argspec ? [split /\s*,\s*/, $argspec] : "",
        };


        #avoid 'use of uninitialized value' warnings
        $entry->{$_} ||= "" for keys %{ $entry };
    }
}



sub write {
    my ($self, $fh, $newentries, $prefix) = @_ ;

    foreach (@$newentries)
        {
        my $line = $self -> {wrapxs} -> mapline_func ($_) ;

        if ($line =~ /\)\((.*?)\)/)
            {
            my @args = split (/,/, $1) ;
            $line .= ' | ' if (@args) ;
            my $i = 0 ;
            foreach (@args)
                {
                $line .= ',' if ($i++ > 0) ;
                /([^ ]+)$/ ;
                my $arg = $1 ;
                $line .= '<' if (/\* \*/) ;
                $line .= $arg ;
                }
            }
        
        $fh -> print ($prefix, $line, "\n") ;
        }
    }