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   204235 use strict;
  2         15  
  2         112  
4 2     2   11 use warnings;
  2         4  
  2         62  
5 2     2   43 use 5.008004;
  2         6  
6 2     2   11 use Test2::API qw( context );
  2         3  
  2         120  
7 2     2   12 use Exporter qw( import );
  2         3  
  2         796  
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.46'; # VERSION
14              
15              
16             sub alien_diag ($@)
17             {
18 2     2 1 46663 my $ctx = context();
19              
20 2         140 my $max = 0;
21 2         6 foreach my $alien (@_)
22             {
23 2         5 foreach my $name (qw( cflags cflags_static libs libs_static version install_type dynamic_libs bin_dir ))
24             {
25 16         26 my $str = "$alien->$name";
26 16 100       27 if(length($str) > $max)
27             {
28 4         6 $max = length($str);
29             }
30             }
31             }
32              
33              
34 2         11 $ctx->diag('');
35 2         490 foreach my $alien (@_) {
36 2         13 $ctx->diag('') for 1..2;
37              
38 2         617 my $found = 0;
39              
40 2         5 foreach my $name (qw( cflags cflags_static libs libs_static version install_type ))
41             {
42 12 100       464 if(eval { $alien->can($name) })
  12         75  
43             {
44 4         7 $found++;
45 4         32 $ctx->diag(sprintf "%-${max}s = %s", "$alien->$name", $alien->$name);
46             }
47             }
48              
49 2         145 foreach my $name (qw( dynamic_libs bin_dir ))
50             {
51 4 100       426 if(eval { $alien->can($name) })
  4         34  
52             {
53 2         4 $found++;
54 2         2 my @list = eval { $alien->$name };
  2         8  
55 2 50       11 next if $@;
56 2         12 $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         173 $ctx->diag('') for 1..2;
63             }
64              
65 2         666 $ctx->release;
66             }
67              
68             1;
69              
70             __END__