File Coverage

inc/My/Module/Test.pm
Criterion Covered Total %
statement 52 59 88.1
branch 11 16 68.7
condition 3 5 60.0
subroutine 10 10 100.0
pod 5 5 100.0
total 81 95 85.2


line stmt bran cond sub pod time code
1             package My::Module::Test;
2              
3 1     1   2026 use strict;
  1         8  
  1         29  
4 1     1   4 use warnings;
  1         2  
  1         26  
5              
6 1     1   5 use Carp;
  1         1  
  1         109  
7 1     1   6 use Exporter qw{ import };
  1         2  
  1         56  
8 1     1   752 use Test::More 0.88;
  1         74637  
  1         9  
9              
10             my @export = qw{
11             decode
12             fails
13             hexify
14             returns
15             round_trip
16             };
17              
18             our @EXPORT = ( @export, @Test::More::EXPORT ); ## no critic (ProhibitAutomaticExportation)
19             our @EXPORT_OK = ( @export, @Test::More::EXPORT_OK );
20              
21             sub decode {
22 12     12 1 6439 splice @_, 1, 0, 'decode';
23 12         40 goto &returns;
24             }
25              
26             sub fails { ## no critic (RequireArgUnpacking)
27 10     10 1 33 my ( $obj, @args ) = @_;
28             ## my $opt = ref $args[0] eq 'HASH' ? shift @args : {};
29 10 50       28 ref $args[0] eq 'HASH' and shift @args; # $opt is unused
30 10         16 my $method = shift @args;
31 10         15 my $name = pop @args;
32 10         12 my $want = pop @args;
33 10 50       22 ref $want or $want = qr<@{[ quotemeta $want ]}>;
  10         202  
34 10         21 local $@;
35 10         52 eval { $obj->$method( @args ); 1 }
  0         0  
36 10 50       15 and do {
37 0         0 @_ = ( "$name did not throw an exception" );
38 0         0 goto &fail;
39             };
40 10         240 @_ = ( $@, $want, $name );
41 10         44 goto &like;
42             }
43              
44             sub hexify {
45 3     3 1 1568 splice @_, 1, 0, { unpack => 'H*' };
46 3         13 goto &returns;
47             }
48              
49             sub returns { ## no critic (RequireArgUnpacking)
50 115     115 1 24520 my ( $obj, @args ) = @_;
51 115 100       313 my $opt = ref $args[0] eq 'HASH' ? shift @args : {};
52 115         172 my $method = shift @args;
53 115         141 my $name = pop @args;
54 115         135 my $want = pop @args;
55 115         125 my $got;
56 115         388 eval { $got = $obj->$method( @args ); 1 }
  115         264  
57 115 50       135 or do {
58 0         0 @_ = ( "$name threw $@" );
59 0         0 goto &fail;
60             };
61             $opt->{unpack}
62 115 100       236 and $got = unpack $opt->{unpack}, $got;
63             $opt->{sprintf}
64 115 100       307 and $got = sprintf $opt->{sprintf}, $got;
65 115         254 @_ = ( $got, $want, $name );
66 115         498 goto &is;
67             }
68              
69             sub round_trip { ## no critic (RequireArgUnpacking)
70 41     41 1 23528 my ( $attr, $value, $opt ) = @_;
71 41   100     190 $opt ||= {};
72 41   33     166 my $name = $opt->{name} || "Round-trip $attr( $value )";
73             my $utdf = eval {
74 41         123 my $obj = Astro::UTDF->new( $attr => $value );
75 41         91 return Astro::UTDF->new( raw_record => $obj->raw_record() );
76 41 50       55 } or do {
77 0         0 @_ = ( "$name threw $@" );
78 0         0 goto &fail;
79             };
80 41         109 @_ = ( $utdf, $opt, $attr, $value, $name );
81 41         120 goto &returns;
82             }
83              
84             1;
85              
86             __END__