Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation #1

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
fail-fast: false
matrix:
cip_tag:
- "5.37"
- "5.39"
- "5.38"
- "5.36"
- "5.34"
- "5.32"
Expand All @@ -27,12 +28,6 @@ jobs:
- "5.24"
- "5.22"
- "5.20"
- "5.18"
- "5.16"
- "5.14"
- "5.12"
- "5.10"
- "5.8"

env:
CIP_TAG: ${{ matrix.cip_tag }}
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Web::LibCURL::FFI ![static](https://github.com/uperl/Web-LibCurl-Version/workflows/static/badge.svg) ![linux](https://github.com/uperl/Web-LibCurl-Version/workflows/linux/badge.svg)

Private class for Web::LibCURL

# SYNOPSIS

```
$ perldoc Web::LibCURL
```

# DESCRIPTION

There is nothing to see here. Please see the main documentation page at
[Web::LibCURL](https://metacpan.org/pod/Web::LibCURL).

# AUTHOR

Graham Ollis <[email protected]>

# COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
5 changes: 2 additions & 3 deletions author.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ pod_coverage:
skip: 0
# format is "Class#method" or "Class",regex allowed
# for either Class or method.
private: []


private:
- Web::LibCURL::FFI
33 changes: 30 additions & 3 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = Net-Swirl-CurlVersion
name = Web-LibCurl-Version
author = Graham Ollis <[email protected]>
license = Perl_5
copyright_holder = Graham Ollis
Expand All @@ -17,9 +17,36 @@ workflow = linux
version_plugin = PkgVersion::Block
irc = irc://irc.perl.org/#native

[Author::Plicease::Core]
diag = +Alien::curl

diag_preamble = | $post_diag = sub {
diag_preamble = | local $@='';
diag_preamble = | my $lib = eval {
diag_preamble = | require Web::LibCURL::FFI;
diag_preamble = | Web::LibCURL::FFI->lib;
diag_preamble = | };
diag_preamble = | diag "warning: $@" if $@;
diag_preamble = | diag "lib = @{[ $lib // 'undef' ]}";
diag_preamble = | $@ = '';
diag_preamble = | my $version = eval {
diag_preamble = | require FFI::Platypus;
diag_preamble = | FFI::Platypus->VERSION("2.00");
diag_preamble = | my $ffi = FFI::Platypus->new( api => 2, lib => [$lib] );
diag_preamble = | $ffi->function('curl_version' => [] => 'string')->call;
diag_preamble = | };
diag_preamble = | diag "warning: $@" if $@;
diag_preamble = | if(defined $version) {
diag_preamble = | diag "version = $_" for split /\s+/, $version;
diag_preamble = | }
diag_preamble = | };

[Author::Plicease::Core]
[Author::Plicease::Upload]
cpan = 0
cpan = 1

[Prereqs / ConfigureRequires]
FFI::CheckLib = 0.30

[DynamicPrereqs / Alien]
-condition = do { require './lib/Web/LibCURL/FFI.pm'; ! eval { Web::LibCURL::FFI->lib; 1 } }
-body = requires('Alien::curl', '0.10');
11 changes: 0 additions & 11 deletions lib/Net/Swirl/CurlVersion.pm

This file was deleted.

32 changes: 32 additions & 0 deletions lib/Web/LibCURL/FFI.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Web::LibCURL::FFI {

use warnings;
use 5.020;
use FFI::CheckLib 0.30 qw( find_lib_or_die );

# ABSTRACT: Private class for Web::LibCURL

=head1 SYNOPSIS

$ perldoc Web::LibCURL

=head1 DESCRIPTION

There is nothing to see here. Please see the main documentation page at
L<Web::LibCURL>.

=cut

sub lib
{
return $ENV{NET_LIBCURL_DLL} //
find_lib_or_die(
lib => 'curl',
symbol => ['curl_version_info'],
alien => ['Alien::curl'],
);
}

}

1;
51 changes: 51 additions & 0 deletions lib/Web/LibCURL/Version.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use warnings;
use 5.020;
use experimental qw( postderef signatures );
use FFI::Platypus 2.00;
use Web::LibCURL::FFI;
use FFI::C;

my $ffi = FFI::Platypus->new(
api => 2,
lib => [Web::LibCURL::FFI->lib],
);

FFI::C->ffi($ffi);

package Web::LibCURL::Version::CurlSslBackend {
FFI::C->struct(curl_ssl_backend => [
id => 'enum',
_name => 'opaque',
]);

sub name ($self)
{
$ffi->cast( opaque => string => $self->_name );
}
}


package Web::LibCURL::Version {

# ABSTRACT: Get version information about curl

=head1 METHODS

=head2 get_ssl_backends

my @backends = Web::LibCURL::Version->get_ssl_backends;

Get the list of SSL backends (as strings).

=cut

sub get_ssl_backends ($class) {
my $ptr;
my $ret = $ffi->function( curl_global_sslset => [ 'senum', 'string', 'opaque*' ] => 'enum' )->call(-1, undef, \$ptr);
# TODO: check ret and throw error
map { $ffi->cast('opaque','curl_ssl_backend', $_)->name } $ffi->cast('opaque','opaque[]',$ptr)->@*;
}

}

1;
109 changes: 109 additions & 0 deletions t/00_diag.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use Test2::V0 -no_srand => 1;
use Config;

eval { require 'Test/More.pm' };

# This .t file is generated.
# make changes instead to dist.ini

my %modules;
my $post_diag;

$modules{$_} = $_ for qw(
Alien::curl
ExtUtils::MakeMaker
FFI::C
FFI::CheckLib
FFI::Platypus
Test2::V0
);

$post_diag = sub {
local $@='';
my $lib = eval {
require Web::LibCURL::FFI;
Web::LibCURL::FFI->lib;
};
diag "warning: $@" if $@;
diag "lib = @{[ $lib // 'undef' ]}";
$@ = '';
my $version = eval {
require FFI::Platypus;
FFI::Platypus->VERSION("2.00");
my $ffi = FFI::Platypus->new( api => 2, lib => [$lib] );
$ffi->function('curl_version' => [] => 'string')->call;
};
diag "warning: $@" if $@;
if(defined $version) {
diag "version = $_" for split /\s+/, $version;
}
};

my @modules = sort keys %modules;

sub spacer ()
{
diag '';
diag '';
diag '';
}

pass 'okay';

my $max = 1;
$max = $_ > $max ? $_ : $max for map { length $_ } @modules;
our $format = "%-${max}s %s";

spacer;

my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV;

if(@keys > 0)
{
diag "$_=$ENV{$_}" for @keys;

if($ENV{PERL5LIB})
{
spacer;
diag "PERL5LIB path";
diag $_ for split $Config{path_sep}, $ENV{PERL5LIB};

}
elsif($ENV{PERLLIB})
{
spacer;
diag "PERLLIB path";
diag $_ for split $Config{path_sep}, $ENV{PERLLIB};
}

spacer;
}

diag sprintf $format, 'perl', "$] $^O $Config{archname}";

foreach my $module (sort @modules)
{
my $pm = "$module.pm";
$pm =~ s{::}{/}g;
if(eval { require $pm; 1 })
{
my $ver = eval { $module->VERSION };
$ver = 'undef' unless defined $ver;
diag sprintf $format, $module, $ver;
}
else
{
diag sprintf $format, $module, '-';
}
}

if($post_diag)
{
spacer;
$post_diag->();
}

spacer;

done_testing;

8 changes: 0 additions & 8 deletions t/net_swirl_curlversion.t

This file was deleted.

13 changes: 13 additions & 0 deletions t/web_libcurl_version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use Test2::V0 -no_srand => 1;
use Web::LibCURL::Version;

subtest 'get_ssl_backends' => sub {

ok 1;
note $_ for Web::LibCURL::Version->get_ssl_backends;

};

done_testing;


Loading