File Coverage

script/tsd-create
Criterion Covered Total %
statement 40 52 76.9
branch 13 26 50.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 59 84 70.2


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 1     1   4368 use strict;
  1         2  
  1         32  
4 1     1   3 use warnings;
  1         1  
  1         45  
5 1     1   800 use Getopt::Long;
  1         12220  
  1         5  
6 1     1   701 use Pod::Usage;
  1         57399  
  1         148  
7 1     1   7 use File::Spec;
  1         1  
  1         26  
8              
9 1     1   456 use Crypt::TSD;
  1         4  
  1         1893  
10              
11             # Command line options
12 1         113752 my $help = 0;
13 1         2 my $version = 0;
14 1         2 my $timestamp_file;
15             my $output_file;
16 1         1 my $verbose = 0;
17              
18             # Parse command line options
19 1 50       9 GetOptions(
20             'help|h' => \$help,
21             'version' => \$version,
22             'timestamp|t=s' => \$timestamp_file,
23             'output|o=s' => \$output_file,
24             'verbose|v' => \$verbose,
25             ) or pod2usage(2);
26              
27             # Show help
28 1 50       987 if ($help) {
29 0         0 pod2usage(-verbose => 2);
30 0         0 exit 0;
31             }
32              
33             # Show version
34 1 50       4 if ($version) {
35 0         0 print "tsd-create version $Crypt::TSD::VERSION\n";
36 0         0 exit 0;
37             }
38              
39             # Get input file from command line
40 1         3 my $input_file = shift @ARGV;
41 1 50       2 if (!$input_file) {
42 0         0 print "Error: Input file required\n";
43 0         0 pod2usage(1);
44             }
45              
46             # Check if input file exists
47 1 50       46 unless (-f $input_file) {
48 0         0 die "Error: Input file '$input_file' not found\n";
49             }
50              
51             # Generate output filename if not provided
52 1 50       3 unless ($output_file) {
53 0         0 $output_file = $input_file;
54 0         0 $output_file =~ s/\.([^.]+)$/.tsd/;
55             }
56              
57             # Check if timestamp file is provided
58 1 50       3 unless ($timestamp_file) {
59 0         0 die "Error: Timestamp file required. Use -t option or --timestamp\n";
60             }
61              
62             # Check if timestamp file exists
63 1 50       9 unless (-f $timestamp_file) {
64 0         0 die "Error: Timestamp file '$timestamp_file' not found\n";
65             }
66              
67 1 50       3 print "Creating TSD file...\n" if $verbose;
68 1 50       3 print "Input file: $input_file\n" if $verbose;
69 1 50       3 print "Timestamp file: $timestamp_file\n" if $verbose;
70 1 50       2 print "Output file: $output_file\n" if $verbose;
71              
72             # Create TSD file
73 1         2 eval {
74 1         13 my $result = Crypt::TSD->write_tds($input_file, $timestamp_file, $output_file);
75 1         16 print "TSD file created successfully: $result\n";
76             };
77 1 50       4 if ($@) {
78 0         0 die "Error creating TSD file: $@\n";
79             }
80              
81 1         0 print "Done!\n";
82              
83             __END__