| 1 | ####################################################################### | ||
| 2 | # $URL: svn+ssh://equilibrious@equilibrious.net/home/equilibrious/svnrepos/chrisdolan/Fuse-PDF/lib/Fuse/PDF/MountPDF.pm $ | ||
| 3 | # $Date: 2008-06-06 22:47:54 -0500 (Fri, 06 Jun 2008) $ | ||
| 4 | # $Author: equilibrious $ | ||
| 5 | # $Revision: 767 $ | ||
| 6 | ######################################################################## | ||
| 7 | |||
| 8 | ## no critic(ErrorHandling::RequireCarping) | ||
| 9 | |||
| 10 | package Fuse::PDF::MountPDF; | ||
| 11 | |||
| 12 | use warnings; | ||
| 13 | use strict; | ||
| 14 | use Getopt::Long qw(GetOptionsFromArray); | ||
| 15 | use Pod::Usage qw(pod2usage); | ||
| 16 | use Fuse::PDF; | ||
| 17 | |||
| 18 | our $VERSION = '0.09'; | ||
| 19 | |||
| 20 | sub run { | ||
| 21 | my ($pkg, @args) = @_; | ||
| 22 | |||
| 23 | my %opts = ( | ||
| 24 | verbose => 0, | ||
| 25 | debug => 0, | ||
| 26 | askforpass => 0, | ||
| 27 | info => 0, | ||
| 28 | delete => 0, | ||
| 29 | backup => 0, | ||
| 30 | rev => 0, | ||
| 31 | keep => 0, | ||
| 32 | fs_name => undef, | ||
| 33 | fuseopts => undef, | ||
| 34 | help => 0, | ||
| 35 | version => 0, | ||
| 36 | ); | ||
| 37 | |||
| 38 | Getopt::Long::Configure('bundling'); | ||
| 39 | GetOptionsFromArray( | ||
| 40 | \@args, | ||
| 41 | 'v|verbose' => \$opts{verbose}, | ||
| 42 | 'd|debug' => \$opts{debug}, | ||
| 43 | 'p|password' => \$opts{askforpass}, | ||
| 44 | 'i|info' => \$opts{info}, | ||
| 45 | 'deletefs' => \$opts{delete}, | ||
| 46 | 'b|backup' => \$opts{backup}, | ||
| 47 | 'r|revision=i' => \$opts{rev}, | ||
| 48 | 'k|keep' => \$opts{keep}, | ||
| 49 | 'f|fs=s' => \$opts{fs_name}, | ||
| 50 | 'fuseopts=s' => \$opts{fuseopts}, | ||
| 51 | 'A|all' => sub {$opts{fs_name} = 'pdf'}, | ||
| 52 | 'h|help' => \$opts{help}, | ||
| 53 | 'V|version' => \$opts{version}, | ||
| 54 | ) or pod2usage(1); | ||
| 55 | |||
| 56 | if ($opts{help}) { | ||
| 57 | pod2usage(-exitval => 'NOEXIT', -verbose => 2); | ||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | if ($opts{version}) { | ||
| 61 | print "Fuse::PDF v$Fuse::PDF::VERSION\n"; | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | if (@args < 1) { | ||
| 66 | pod2usage(-exitval => 'NOEXIT', -verbose => 1); | ||
| 67 | return 1; | ||
| 68 | } | ||
| 69 | if (@args < 2 && !$opts{info} && !$opts{delete}) { | ||
| 70 | pod2usage(-exitval => 'NOEXIT', -verbose => 1); | ||
| 71 | return 1; | ||
| 72 | } | ||
| 73 | |||
| 74 | my $filename = shift @args; | ||
| 75 | my $mountdir = shift @args; | ||
| 76 | |||
| 77 | my $pdf_opts = [q{}, q{}, { prompt_for_password => $opts{askforpass} }]; | ||
| 78 | my $fuse = Fuse::PDF->new($filename, { | ||
| 79 | pdf_constructor => $pdf_opts, | ||
| 80 | fs_name => $opts{fs_name}, | ||
| 81 | revision => $opts{rev}, | ||
| 82 | backup => $opts{backup}, | ||
| 83 | compact => !$opts{keep}, | ||
| 84 | }) or die 'Failed to open the PDF'; | ||
| 85 | |||
| 86 | if ($opts{info}) { | ||
| 87 | print $fuse->fs->to_string; | ||
| 88 | } elsif ($opts{delete}) { | ||
| 89 | $fuse->fs->deletefs($filename); | ||
| 90 | } else { | ||
| 91 | $fuse->mount($mountdir, { | ||
| 92 | $opts{debug} ? ( debug => 1 ) : (), | ||
| 93 | $opts{fuseopts} ? ( mountopts => $opts{fuseopts} ) : (), | ||
| 94 | }); | ||
| 95 | } | ||
| 96 | |||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | |||
| 100 | 1; | ||
| 101 | |||
| 102 | __END__ |