File Coverage

blib/lib/PDF/Collage.pm
Criterion Covered Total %
statement 71 80 88.7
branch 17 34 50.0
condition 5 15 33.3
subroutine 16 17 94.1
pod 5 5 100.0
total 114 151 75.5


line stmt bran cond sub pod time code
1             package PDF::Collage;
2 2     2   5625 use v5.24;
  2         14  
3 2     2   8 use warnings;
  2         4  
  2         46  
4 2     2   553 use experimental qw< signatures >;
  2         2847  
  2         9  
5 2     2   234 no warnings qw< experimental::signatures >;
  2         4  
  2         108  
6             { our $VERSION = '0.002' }
7              
8 2     2   12 use Carp;
  2         3  
  2         89  
9 2     2   848 use English qw< -no_match_vars >;
  2         5699  
  2         9  
10 2     2   1729 use JSON::PP qw< decode_json >;
  2         27874  
  2         143  
11 2     2   14 use Scalar::Util qw< blessed >;
  2         4  
  2         112  
12 2     2   874 use Data::Resolver qw< file_to_data >;
  2         5609  
  2         102  
13 2     2   817 use PDF::Collage::Template ();
  2         7  
  2         56  
14 2     2   934 use PDF::Collage::TemplatesCollection ();
  2         7  
  2         55  
15              
16 2     2   10 use Exporter 'import';
  2         4  
  2         1237  
17             our @EXPORT_OK = qw<
18             collage
19             collage_from_definition
20             collage_from_dir
21             collage_from_resolver
22             collage_from_tar
23             >;
24             our %EXPORT_TAGS = (all => [@EXPORT_OK],);
25              
26 6     6 1 11630 sub collage ($input, @args) {
  6         10  
  6         15  
  6         8  
27 6 50       30 my %args = @args == 0 ? (auto => $input) : ($input, @args);
28             return collage_from_resolver($args{resolver})
29 6 100       25 if defined $args{resolver};
30 5 50       16 return collage_from_dir($args{dir}) if defined $args{dir};
31 5 50       14 return collage_from_tar($args{tar}) if defined $args{tar};
32             return collage_from_definition($args{definition})
33 5 50       13 if defined $args{definition};
34 5 50       16 if (defined(my $auto = $args{auto})) {
35 5 50       20 return collage_from_resolver($auto) if blessed($auto);
36              
37 5         13 my $ar = ref($auto);
38 5 50 33     34 if ($ar eq '' && $auto =~ m{\A [\[\{]}mxs) {
39 0         0 $auto = decode_json($auto);
40 0         0 $ar = ref($auto);
41             }
42 5 50 33     52 return collage_from_definition($auto)
      33        
      33        
43             if ($ar eq '' && $ar =~ m{\A \s* [\[\{] }mxs)
44             || ($ar eq 'HASH')
45             || ($ar eq 'ARRAY');
46              
47 5 50       12 croak "cannot handle auto input of type $ar" if $ar ne '';
48 5 50       108 croak "cannot use provided automatic hint" unless -r $auto;
49              
50 5 100       86 return collage_from_dir($auto) if -d $auto;
51              
52 2 50       97 open my $fh, '<:raw', $auto or croak "open('$auto'): $OS_ERROR";
53 2         8 my $first = '';
54 2         64 my $n = read $fh, $first, 1;
55 2 50       11 croak "sysread() on '$auto': $OS_ERROR" unless defined $n;
56 2         29 close $fh;
57 2 50 33     17 return collage_from_definition(file_to_data($auto))
58             if ($first eq '{') || ($first eq '{');
59 2         10 return collage_from_tar($auto);
60             } ## end if (defined(my $auto =...))
61              
62 0         0 croak 'no useful input';
63             } ## end sub collage
64              
65 0     0 1 0 sub collage_from_definition ($def) {
  0         0  
  0         0  
66 0 0       0 $def = decode_json($def) unless ref $def;
67 0 0       0 $def = {commands => $def} if ref($def) eq 'ARRAY';
68 0         0 return PDF::Collage::Template->new($def->%*);
69             }
70              
71 3     3 1 9 sub collage_from_dir ($path) {
  3         5  
  3         4  
72 3         18 return collage_from_resolver(
73             {class => 'Data::Resolver::FromDir', root => $path});
74             }
75              
76 6     6 1 10 sub collage_from_resolver ($resolver) {
  6         9  
  6         10  
77 6         161 return PDF::Collage::TemplatesCollection->new(resolver => $resolver);
78             }
79              
80 2     2 1 4 sub collage_from_tar ($path) {
  2         5  
  2         4  
81 2         14 return collage_from_resolver(
82             {class => 'Data::Resolver::FromTar', root => $path});
83             }
84              
85             1;