view release on metacpan or search on metacpan
lib/ExtUtils/H2PM.pm view on Meta::CPAN
qq[ printf("$basename=%lu,", (unsigned long)sizeof($basename));],
( map { " " . $_->{gen_c}->() } @memberhandlers ),
qq[ printf("\\n");],
" }";
push @fragments, "#endif" if $params{ifdef};
push @genblocks, [ $basename => sub {
my ( $result ) = @_;
return () unless defined $result;
my @result = split m/,/, $result;
my $curpos = 0;
my $format = "";
my $sizeof = shift @result;
my ( @postargs, @preret );
foreach my $def ( @result ) {
lib/ExtUtils/H2PM.pm view on Meta::CPAN
my $output;
{
open( my $runh, "./$exename |" ) or die "Cannot pipeopen $exename - $!";
local $/;
$output = <$runh>;
}
unlink $exename;
my %results = map { m/^(\w+)=(.*)$/ } split m/\n/, $output;
my $perl = "";
my @bodylines;
# Evaluate these first, so they have a chance to push_export()
foreach my $genblock ( @genblocks ) {
my ( $key, $code ) = @$genblock;
push @bodylines, $code->( $results{$key} );
t/01constant.t view on Meta::CPAN
my $code;
$code = do {
module "TEST";
include "t/test.h", local => 1;
constant "DEFINED_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
push \@EXPORT_OK, 'DEFINED_CONSTANT';
use constant DEFINED_CONSTANT => 10;
1;
EOPERL
'Simple constant' );
t/01constant.t view on Meta::CPAN
10,
'Code exports a constant of the right value' );
$code = do {
module "TEST";
include "t/test.h", local => 1;
constant "DEFINED_CONSTANT", name => "CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
push \@EXPORT_OK, 'CONSTANT';
use constant CONSTANT => 10;
1;
EOPERL
'Simple constant renamed' );
$code = do {
module "TEST";
include "t/test.h", local => 1;
no_export;
constant "DEFINED_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use constant DEFINED_CONSTANT => 10;
1;
EOPERL
'No-export constant' );
$code = do {
module "TEST";
include "t/test.h", local => 1;
constant "ENUMERATED_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use constant ENUMERATED_CONSTANT => 20;
1;
EOPERL
'Enumerated constant' );
$code = do {
module "TEST";
include "t/test.h", local => 1;
constant "STATIC_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use constant STATIC_CONSTANT => 30;
1;
EOPERL
'Static constant' );
$code = do {
module "TEST";
use_export;
include "t/test.h", local => 1;
constant "MISSING_CONSTANT", ifdef => "MISSING_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
1;
EOPERL
'Missing constant' );
done_testing;
t/02structure-numeric.t view on Meta::CPAN
module "TEST";
include "t/test.h", local => 1;
structure "struct point",
members => [
x => member_numeric,
y => member_numeric,
];
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use Carp;
push \@EXPORT_OK, 'pack_point', 'unpack_point';
sub pack_point
{
\@_ == 2 or croak "usage: pack_point(x, y)";
my \@v = \@_;
t/02structure-numeric.t view on Meta::CPAN
structure "struct point",
pack_func => "point_packing_function",
unpack_func => "point_unpacking_function",
members => [
x => member_numeric,
y => member_numeric,
];
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use Carp;
push \@EXPORT_OK, 'point_packing_function', 'point_unpacking_function';
sub point_packing_function
{
\@_ == 2 or croak "usage: point_packing_function(x, y)";
my \@v = \@_;
t/02structure-numeric.t view on Meta::CPAN
module "TEST";
include "t/test.h", local => 1;
structure "struct msghdr",
members => [
cmd => member_numeric,
vers => member_numeric,
];
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use Carp;
push \@EXPORT_OK, 'pack_msghdr', 'unpack_msghdr';
sub pack_msghdr
{
\@_ == 2 or croak "usage: pack_msghdr(cmd, vers)";
my \@v = \@_;
t/02structure-numeric.t view on Meta::CPAN
module "TEST";
include "t/test.h", local => 1;
structure "struct missing",
members => [
none => member_numeric,
],
ifdef => "HAS_STRUCT_MISSING";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
1;
EOPERL
'Missing structure' );
done_testing;
t/03structure-strarray.t view on Meta::CPAN
module "TEST";
include "t/test.h", local => 1;
structure "struct idname",
members => [
id => member_numeric,
name => member_strarray,
];
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use Carp;
push \@EXPORT_OK, 'pack_idname', 'unpack_idname';
sub pack_idname
{
\@_ == 2 or croak "usage: pack_idname(id, name)";
my \@v = \@_;
t/04structure-constant.t view on Meta::CPAN
structure "struct idname",
members => [
id => member_constant("ENUMERATED_CONSTANT"),
name => member_strarray,
];
gen_output;
};
my $FILE = __FILE__;
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $FILE
use Carp;
push \@EXPORT_OK, 'ENUMERATED_CONSTANT', 'pack_idname', 'unpack_idname';
use constant ENUMERATED_CONSTANT => 20;
sub pack_idname
{
\@_ == 1 or croak "usage: pack_idname(name)";
t/10structure-with-tail.t view on Meta::CPAN
include "t/test.h", local => 1;
structure "struct msghdr",
with_tail => 1,
members => [
cmd => member_numeric,
vers => member_numeric,
];
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use Carp;
push \@EXPORT_OK, 'pack_msghdr', 'unpack_msghdr';
sub pack_msghdr
{
\@_ >= 2 or croak "usage: pack_msghdr(cmd, vers, [tail])";
my \@v = \@_;
t/11structure-args-hashref.t view on Meta::CPAN
include "t/test.h", local => 1;
structure "struct point",
arg_style => "hashref",
members => [
x => member_numeric,
y => member_numeric,
];
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
use Carp;
push \@EXPORT_OK, 'pack_point', 'unpack_point';
sub pack_point
{
ref(\$_[0]) eq "HASH" or croak "usage: pack_point(\\%args)";
my \@v = \@{\$_[0]}{'x', 'y'};
t/20include_path.t view on Meta::CPAN
my $code;
$code = do {
module "TEST";
include_path "t";
include "test.h", local => 1;
constant "DEFINED_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
push \@EXPORT_OK, 'DEFINED_CONSTANT';
use constant DEFINED_CONSTANT => 10;
1;
EOPERL
'include_path' );
t/21define.t view on Meta::CPAN
my $code;
$code = do {
module "TEST";
include "t/test.h", local => 1;
define "EXTERNAL_CONSTANT", 40;
constant "EXTERNAL_CONSTANT";
gen_output;
};
is_deeply( [ split m/\n/, $code ],
[ split m/\n/, <<"EOPERL" ],
package TEST;
# This module was generated automatically by ExtUtils::H2PM from $0
push \@EXPORT_OK, 'EXTERNAL_CONSTANT';
use constant EXTERNAL_CONSTANT => 40;
1;
EOPERL
'define' );