File Coverage

blib/lib/Test/Alien/Diag.pm
Criterion Covered Total %
statement 41 41 100.0
branch 9 10 90.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 57 58 98.2


line stmt bran cond sub pod time code
1             package Test::Alien::Diag;
2              
3 2     2   231130 use strict;
  2         10  
  2         60  
4 2     2   11 use warnings;
  2         4  
  2         59  
5 2     2   45 use 5.008004;
  2         6  
6 2     2   13 use Test2::API qw( context );
  2         4  
  2         102  
7 2     2   14 use Exporter qw( import );
  2         4  
  2         862  
8              
9             our @EXPORT = qw( alien_diag );
10             our @EXPORT_OK = @EXPORT;
11              
12             # ABSTRACT: Print out standard diagnostic for Aliens in the test step.
13             our $VERSION = '2.45'; # VERSION
14              
15              
16             sub alien_diag ($@)
17             {
18 2     2 1 53139 my $ctx = context();
19              
20 2         179 my $max = 0;
21 2         6 foreach my $alien (@_)
22             {
23 2         8 foreach my $name (qw( cflags cflags_static libs libs_static version install_type dynamic_libs bin_dir ))
24             {
25 16         32 my $str = "$alien->$name";
26 16 100       36 if(length($str) > $max)
27             {
28 4         8 $max = length($str);
29             }
30             }
31             }
32              
33              
34 2         11 $ctx->diag('');
35 2         530 foreach my $alien (@_) {
36 2         13 $ctx->diag('') for 1..2;
37              
38 2         750 my $found = 0;
39              
40 2         7 foreach my $name (qw( cflags cflags_static libs libs_static version install_type ))
41             {
42 12 100       548 if(eval { $alien->can($name) })
  12         79  
43             {
44 4         7 $found++;
45 4         36 $ctx->diag(sprintf "%-${max}s = %s", "$alien->$name", $alien->$name);
46             }
47             }
48              
49 2         179 foreach my $name (qw( dynamic_libs bin_dir ))
50             {
51 4 100       569 if(eval { $alien->can($name) })
  4         35  
52             {
53 2         4 $found++;
54 2         5 my @list = eval { $alien->$name };
  2         8  
55 2 50       13 next if $@;
56 2         16 $ctx->diag(sprintf "%-${max}s = %s", "$alien->$name", $_) for @list;
57             }
58             }
59              
60 2 100       185 $ctx->diag("no diagnostics found for $alien") unless $found;
61              
62 2         225 $ctx->diag('') for 1..2;
63             }
64              
65 2         719 $ctx->release;
66             }
67              
68             1;
69              
70             __END__