File Coverage

blib/lib/Alien/Build/Plugin/Probe/Vcpkg.pm
Criterion Covered Total %
statement 11 50 22.0
branch 0 24 0.0
condition 0 5 0.0
subroutine 4 7 57.1
pod 1 1 100.0
total 16 87 18.3


line stmt bran cond sub pod time code
1             package Alien::Build::Plugin::Probe::Vcpkg;
2              
3 2     2   1329 use strict;
  2         6  
  2         67  
4 2     2   8 use warnings;
  2         6  
  2         41  
5 2     2   31 use 5.008004;
  2         7  
6 2     2   349 use Alien::Build::Plugin;
  2         5  
  2         21  
7              
8             # ABSTRACT: Probe for system libraries using Vcpkg
9             our $VERSION = '2.47'; # VERSION
10              
11              
12             has '+name';
13             has 'lib';
14             has 'ffi_name';
15             has 'include';
16              
17             sub init
18             {
19 0     0 1   my($self, $meta) = @_;
20              
21 0 0         if(defined $self->include)
    0          
22             {
23 0           $meta->add_requires('configure' => 'Alien::Build::Plugin::Probe::Vcpkg' => '2.16' );
24             }
25             elsif(defined $self->ffi_name)
26             {
27 0           $meta->add_requires('configure' => 'Alien::Build::Plugin::Probe::Vcpkg' => '2.14' );
28             }
29             else
30             {
31 0           $meta->add_requires('configure' => 'Alien::Build::Plugin::Probe::Vcpkg' => '0' );
32             }
33              
34 0 0         if($meta->prop->{platform}->{compiler_type} eq 'microsoft')
35             {
36             $meta->register_hook(
37             probe => sub {
38 0     0     my($build) = @_;
39              
40 0           $build->hook_prop->{probe_class} = __PACKAGE__;
41 0           $build->hook_prop->{probe_instance_id} = $self->instance_id;
42              
43 0           eval {
44 0           require Win32::Vcpkg;
45 0           require Win32::Vcpkg::List;
46 0           require Win32::Vcpkg::Package;
47 0           Win32::Vcpkg->VERSION('0.02');
48             };
49 0 0         if(my $error = $@)
50             {
51 0           $build->log("unable to load Win32::Vcpkg: $error");
52 0           return 'share';
53             }
54              
55 0           my $package;
56 0 0         if($self->name)
    0          
57             {
58 0           $package = Win32::Vcpkg::List->new
59             ->search($self->name, include => $self->include);
60             }
61             elsif($self->lib)
62             {
63 0           $package = eval { Win32::Vcpkg::Package->new( lib => $self->lib, include => $self->include) };
  0            
64 0 0         return 'share' if $@;
65             }
66             else
67             {
68 0           $build->log("you must provode either name or lib property for Probe::Vcpkg");
69 0           return 'share';
70             }
71              
72 0           my $version = $package->version;
73 0 0         $version = 'unknown' unless defined $version;
74              
75 0           $build->install_prop->{plugin_probe_vcpkg}->{$self->instance_id} = {
76             version => $version,
77             cflags => $package->cflags,
78             libs => $package->libs,
79             };
80 0           $build->hook_prop->{version} = $version;
81 0 0         $build->install_prop->{plugin_probe_vcpkg}->{$self->instance_id}->{ffi_name} = $self->ffi_name
82             if defined $self->ffi_name;
83 0           return 'system';
84             },
85 0           );
86              
87             $meta->register_hook(
88             gather_system => sub {
89 0     0     my($build) = @_;
90              
91             return if $build->hook_prop->{name} eq 'gather_system'
92 0 0 0       && ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id;
      0        
93              
94 0 0         if(my $c = $build->install_prop->{plugin_probe_vcpkg}->{$self->instance_id})
95             {
96 0 0         $build->runtime_prop->{version} = $c->{version} unless defined $build->runtime_prop->{version};
97 0           $build->runtime_prop->{$_} = $c->{$_} for grep { defined $c->{$_} } qw( cflags libs ffi_name );
  0            
98             }
99             },
100 0           );
101             }
102             }
103              
104             1;
105              
106             __END__