diff options
author | Salvatore Bonaccorso <salvatore.bonaccorso@gmail.com> | 2009-10-01 06:49:05 +0000 |
---|---|---|
committer | Salvatore Bonaccorso <salvatore.bonaccorso@gmail.com> | 2009-10-01 06:49:05 +0000 |
commit | 01170f24502ec2597e8800b5567a69d8550ca5fc (patch) | |
tree | 9d02ce49e16ba6913c54b48f8b69e6b1ee7dfc85 | |
parent | f8c643ce829b0dd14f8d3cdf58b4d811ba64c9c8 (diff) |
[svn-upgrade] Integrating new upstream version, libgnupg-interface-perl (0.42)
44 files changed, 2749 insertions, 936 deletions
@@ -1,3 +1,19 @@ +0.42 Wed Sep 30 23:20:58 JST 2009 + + * Support for GPG2 + +0.41_01 Fri Sep 25 02:56:33 JST 2009 + + * Beginnings of support for GPG2 + +0.40_04 Tue Apr 21 19:50:12 JST 2009 + + * Use Any::Moose instead of Moose for Mouse celerity (Sartak) + +0.40_1 Sat Nov 15 12:35:59 EST 2008 + * [rt.cpan.org #40963] Replace Class::MethodMaker with Moose (Chris Prather) + + 0.36 Mon Aug 13 12:16:38 EDT 2007 * [rt.cpan.org #28814] - Performance improvement from mehradek (Radoslaw Zielinski) @@ -1,50 +1,60 @@ -SIGNATURE -COPYING ChangeLog -MANIFEST -Makefile.PL -NEWS -README -THANKS +COPYING +inc/Module/Install.pm +inc/Module/Install/Base.pm +inc/Module/Install/Can.pm +inc/Module/Install/Fetch.pm +inc/Module/Install/Makefile.pm +inc/Module/Install/Metadata.pm +inc/Module/Install/Win32.pm +inc/Module/Install/WriteAll.pm lib/GnuPG/Fingerprint.pm lib/GnuPG/Handles.pm +lib/GnuPG/HashInit.pm lib/GnuPG/Interface.pm lib/GnuPG/Key.pm lib/GnuPG/Options.pm lib/GnuPG/PrimaryKey.pm lib/GnuPG/PublicKey.pm -lib/GnuPG/UserId.pm lib/GnuPG/SecretKey.pm lib/GnuPG/Signature.pm lib/GnuPG/SubKey.pm -t/GnuPG/ComparableFingerprint.pm -t/GnuPG/ComparableKey.pm -t/GnuPG/ComparablePrimaryKey.pm -t/GnuPG/ComparablePublicKey.pm -t/GnuPG/ComparableSecretKey.pm -t/GnuPG/ComparableSignature.pm -t/GnuPG/ComparableSubKey.pm -t/GnuPG/ComparableUserId.pm -t/Fingerprint.t -t/Interface.t -t/MyTest.pm -t/MyTestSpecific.pm -t/UserId.t +lib/GnuPG/UserId.pm +Makefile.PL +MANIFEST This list of files +MANIFEST.SKIP +META.yml +NEWS +README +SIGNATURE t/clearsign.t t/decrypt.t t/detach_sign.t t/encrypt.t t/encrypt_symmetrically.t t/export_keys.t +t/Fingerprint.t t/get_public_keys.t t/get_secret_keys.t +t/GnuPG/ComparableFingerprint.pm +t/GnuPG/ComparableKey.pm +t/GnuPG/ComparablePrimaryKey.pm +t/GnuPG/ComparablePublicKey.pm +t/GnuPG/ComparableSecretKey.pm +t/GnuPG/ComparableSignature.pm +t/GnuPG/ComparableSubKey.pm +t/GnuPG/ComparableUserId.pm t/import_keys.t +t/Interface.t t/list_public_keys.t t/list_secret_keys.t t/list_sigs.t +t/MyTest.pm +t/MyTestSpecific.pm t/passphrase_handling.t t/sign.t t/sign_and_encrypt.t +t/UserId.t t/verify.t t/wrap_call.t test/encrypted.1.gpg @@ -54,15 +64,24 @@ test/passphrase test/plain.1.txt test/public-keys-sigs/1.0.test test/public-keys-sigs/1.1.test +test/public-keys-sigs/1.out test/public-keys-sigs/2.0.test test/public-keys-sigs/2.1.test +test/public-keys-sigs/2.out test/public-keys/1.0.test test/public-keys/1.1.test +test/public-keys/1.out test/public-keys/2.0.test test/public-keys/2.1.test +test/public-keys/2.out test/pubring.gpg +test/random_seed test/secret-keys/1.0.test +test/secret-keys/1.out test/secret-keys/2.0.test +test/secret-keys/2.out test/secring.gpg test/signed.1.asc -META.yml Module meta-data (added by MakeMaker) +test/temp +test/trustdb.gpg +THANKS diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..ae36ac8 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,12 @@ +TODO +Makefile$ +Makefile.old$ +blib +pm_to_blib +.swp$ +~$ +.tmp$ +.bak$ +.git/ +.gitignore$ +.shipit$ @@ -1,14 +1,25 @@ ---- #YAML:1.0 -name: GnuPG-Interface -version: 0.36 -abstract: supply object methods for interacting with GnuPG -license: ~ -generated_by: ExtUtils::MakeMaker version 6.31 -distribution_type: module -requires: - Class::MethodMaker: 1 -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.2.html - version: 1.2 +--- +abstract: 'supply object methods for interacting with GnuPG' author: - - Frank J. Tobin + - 'Frank J. Tobin' +build_requires: + ExtUtils::MakeMaker: 6.42 +configure_requires: + ExtUtils::MakeMaker: 6.42 +distribution_type: module +generated_by: 'Module::Install version 0.91' +license: perl +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: 1.4 +name: GnuPG-Interface +no_index: + directory: + - inc + - t + - test +requires: + Any::Moose: 0.04 +resources: + license: http://dev.perl.org/licenses/ +version: 0.42 diff --git a/Makefile.PL b/Makefile.PL index 438c043..38b8899 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,54 +1,24 @@ -use 5.005; - use strict; -use English qw( -no_match_vars ); -use ExtUtils::MakeMaker; - -use File::Find; -use File::Spec; - -$WARNING = 1; - -my $gnupg_base = 'lib/GnuPG'; -my $gnupg_install_base = "\$(INST_LIBDIR)"; -my %pm_install_hash = (); - -my $gpg_find = 'which gpg'; -print "$gpg_find ... "; -system($gpg_find); -if ($CHILD_ERROR != 0) -{ - die "gpg (GnuPG) not found"; +use warnings; +use inc::Module::Install; + +for my $gpg qw(gpg gpg2) { + my $gpg_find = "which $gpg"; + print "$gpg_find ... "; + system($gpg_find); + if ( $? != 0 ) { + die "gpg (GnuPG) not found"; + } else { last } } -find( \&set_pm_install_hash, $gnupg_base ); - -sub set_pm_install_hash -{ - return unless /\.pm$/; - - my $install_path = $File::Find::name; - $install_path =~ s/$gnupg_base/$gnupg_install_base/; - $pm_install_hash{$File::Find::name} = $install_path; -} +author 'Frank J. Tobin'; +abstract 'supply object methods for interacting with GnuPG'; +name 'GnuPG-Interface'; +version_from 'lib/GnuPG/Interface.pm'; +requires 'Any::Moose' => '0.04'; +license 'perl'; -WriteMakefile - ( AUTHOR => 'Frank J. Tobin', - ABSTRACT => 'supply object methods for interacting with GnuPG', - NAME => 'GnuPG::Interface', - VERSION_FROM => File::Spec->catfile( $gnupg_base, 'Interface.pm' ), - - PREREQ_PM => { - 'Class::MethodMaker' => 1.00, - }, - - PM => { %pm_install_hash }, - - dist => { - COMPRESS => 'gzip', - SUFFIX => 'gz', - }, - clean => { FILES => "test/*-keys*/*.out test/random_seed test/trustdb.gpg test/temp" } - ); +sign(); +WriteAll(); @@ -15,23 +15,34 @@ not run its Makefile.PL or Build.PL. Hash: SHA1 SHA1 187c2cfc1fc31d42c18d5b1653afa1a905bf266c COPYING -SHA1 5df20960703ba8651c67f36ed4ed601e0d0d4406 ChangeLog -SHA1 ae07f475fb7a1668d2ffcfe090f99961ddb77d41 MANIFEST -SHA1 7beeb96d32ce9fd224db1fe25052960fe640c464 Makefile.PL +SHA1 f251a3e5177b2672258b376fba43d30a9b7e84a7 ChangeLog +SHA1 ed3a5d8cb2a7931578c48e84ad2a1191ec30c1e1 MANIFEST +SHA1 13bf6b4540170c65244363d8b24b041180d66765 MANIFEST.SKIP +SHA1 dcd64a562d9e46b041d268ec3853de54273ed8a3 META.yml +SHA1 92f709ea03b0b69509ad258553c82905b533d610 Makefile.PL SHA1 d6e32c5128419cdbfe6e6f846ff7f64fc0adac2f NEWS SHA1 1047dc54823b1321e939274dd261d8e40febee24 README SHA1 df07bf5a2dd74ffe4b69dff3063f68879cf9e355 THANKS -SHA1 d24732774ba9a4cbdda50a384cf8be663ecf91e6 lib/GnuPG/Fingerprint.pm -SHA1 adafb2ff1a23ca10691bba5ab96d5e3c77bdaec5 lib/GnuPG/Handles.pm -SHA1 70b42a050f887196450846dfe9436992cc29a921 lib/GnuPG/Interface.pm -SHA1 742929758535fe82fe609a7d668355e7142eff8c lib/GnuPG/Key.pm -SHA1 90204e29f8ba26267a882d1e2b1b4e56fefeeeeb lib/GnuPG/Options.pm -SHA1 f84ba91c4ed3e47f1b5bba20c02e087ee3d90e73 lib/GnuPG/PrimaryKey.pm -SHA1 d13ae0d9fff63041cbe9f89cb6bcf329e0b4d4e6 lib/GnuPG/PublicKey.pm -SHA1 cbe00ca1d42f6a6dff5bc0cc3e3a9bf6687440fc lib/GnuPG/SecretKey.pm -SHA1 ca90003145b6b6c71a963b96da8415e7f22e9c20 lib/GnuPG/Signature.pm -SHA1 76a6d21bacb3d8c8e18715aaa2c06a0db695f4b0 lib/GnuPG/SubKey.pm -SHA1 192f417f4bdb5398130362544cf6fb4c00b4e928 lib/GnuPG/UserId.pm +SHA1 fd5f3c4f0418efee3b9b16cf8c3902e8374909df inc/Module/Install.pm +SHA1 7cd7c349afdf3f012e475507b1017bdfa796bfbd inc/Module/Install/Base.pm +SHA1 ba186541bbf6439111f01fc70769cf24d22869bf inc/Module/Install/Can.pm +SHA1 aaa50eca0d7751db7a4d953fac9bc72c6294e238 inc/Module/Install/Fetch.pm +SHA1 3e83972921d54198d1246f7278f08664006cd65d inc/Module/Install/Makefile.pm +SHA1 12bf1867955480d47d5171a9e9c6a96fabe0b58f inc/Module/Install/Metadata.pm +SHA1 f7ee667e878bd2faf22ee9358a7b5a2cc8e91ba4 inc/Module/Install/Win32.pm +SHA1 8ed29d6cf217e0977469575d788599cbfb53a5ca inc/Module/Install/WriteAll.pm +SHA1 ab92e0f4a0cb79eeead245e792fa02baccafb4fe lib/GnuPG/Fingerprint.pm +SHA1 8852195e80823c93b6aed673e69433ae3ea46d26 lib/GnuPG/Handles.pm +SHA1 779e6a921fa104e8f16fd4a6d38f670074592811 lib/GnuPG/HashInit.pm +SHA1 745384e607761a4eb3b758c330fd7c62148db066 lib/GnuPG/Interface.pm +SHA1 2a0ccd5ef55b4f6dec5f7464c86e989674623ef1 lib/GnuPG/Key.pm +SHA1 f233f9b250b603c5f1f056c85b5f034b3e4e1ef9 lib/GnuPG/Options.pm +SHA1 f6cdea5f09b944e81a66a1f554db60c1b536d1d2 lib/GnuPG/PrimaryKey.pm +SHA1 4473eeb91061fa09c2fe779ed2fb5c84bd7b4c05 lib/GnuPG/PublicKey.pm +SHA1 1aa4521f22337b6a8d8c7980a97ea9f692528038 lib/GnuPG/SecretKey.pm +SHA1 5e4721c2ba905a3e2e1583a540b72e0ffb5cd5e8 lib/GnuPG/Signature.pm +SHA1 1cd30e5f429d1dbfb4b36ef3b3ab35013ca0a101 lib/GnuPG/SubKey.pm +SHA1 298a897d30956e74a374f4e7d790680798811bf6 lib/GnuPG/UserId.pm SHA1 367fdb308292a9c005afffef49ff9096a20a4da3 t/Fingerprint.t SHA1 501ac69701ce51b3dd98f7f82a3c19a4fba6c3bd t/GnuPG/ComparableFingerprint.pm SHA1 ac3e4f640c0b7ffc2e6cc1a9d08546927614a456 t/GnuPG/ComparableKey.pm @@ -43,7 +54,7 @@ SHA1 11224faf53b09044aa119fe40c09553a3bf4a091 t/GnuPG/ComparableSubKey.pm SHA1 69961a5efc193745729505e317db48cccd728cf0 t/GnuPG/ComparableUserId.pm SHA1 8791d014e4efd4cf11998386e1651cc4eb16dd26 t/Interface.t SHA1 698ec633be083b7e762331f1a5106c1618c74dd3 t/MyTest.pm -SHA1 6fb9814ee5634f8c121ad4c38babb8f04334c6d9 t/MyTestSpecific.pm +SHA1 52114a082f32bdbf284eb968afe458866854996e t/MyTestSpecific.pm SHA1 ccd942d9f00627253d7eb9c011116dc5671639b8 t/UserId.t SHA1 16ac3a802f059cad9b7a0567eebe8b9599cc2551 t/clearsign.t SHA1 fab3deb7f60a0b5aae2f92b1c39804d1a4df2848 t/decrypt.t @@ -69,21 +80,30 @@ SHA1 4e1243bd22c66e76c2ba9eddc1f91394e57f9f83 test/passphrase SHA1 59c0e6436b38645144d17ce11ac4aabfdd43e960 test/plain.1.txt SHA1 7d94ea032bdbb0104c1dc73583ec64ade6294495 test/public-keys-sigs/1.0.test SHA1 63d93054decf9ff6c2dc99eb03f131b55af4ee43 test/public-keys-sigs/1.1.test +SHA1 f131ed203b88c35d78bf420b4739bd60fe9fa319 test/public-keys-sigs/1.out SHA1 bd9892a93f802c68109b11b756f79f6b0292eb1a test/public-keys-sigs/2.0.test SHA1 73d90696020a01753cda984262a2831dcc6ac0d7 test/public-keys-sigs/2.1.test +SHA1 1537de3e2bccfb57b4c515fd6532cdbe9313096f test/public-keys-sigs/2.out SHA1 82d483adc6d203c79856a70dd259370f6efdeef7 test/public-keys/1.0.test SHA1 86056ad37b8bb67d55ac61b5d5a27ac4bbd1cceb test/public-keys/1.1.test +SHA1 18365fae169164b18e855861e74fa2a84031b53b test/public-keys/1.out SHA1 a8e97a2439671dae0dd29a2404c321ccb686ba7a test/public-keys/2.0.test SHA1 54d2c13bf3b73b7582edef091175dfe3763ddf59 test/public-keys/2.1.test +SHA1 18365fae169164b18e855861e74fa2a84031b53b test/public-keys/2.out SHA1 5fa3777416ba09b8a396113dce6ddbf6a73b4b74 test/pubring.gpg +SHA1 734cbb6b69ba568151863cadcf5f50d2a410381a test/random_seed SHA1 e740841597775e3da265ec14e411ed0432bae5e2 test/secret-keys/1.0.test +SHA1 e740841597775e3da265ec14e411ed0432bae5e2 test/secret-keys/1.out SHA1 3bd6135279f9ae23e32680707c6170910421e5de test/secret-keys/2.0.test +SHA1 d15fbde50ae625d033b9cb903a03596fe3cb7e2e test/secret-keys/2.out SHA1 4ae7541bb82abaef5573e61582c4dd4f96cc7f63 test/secring.gpg SHA1 981418a80bf7dab91b63608cfd1ddf5091f89ad7 test/signed.1.asc +SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709 test/temp +SHA1 191d91c4fe445c5f2906468b90b95d288ea3b8c0 test/trustdb.gpg -----BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.3 (Darwin) +Version: GnuPG v1.4.9 (GNU/Linux) -iD8DBQFGwIXrEi9d9xCOQEYRAhSQAJ9U5f8EkJZne2zphN0bH0n4LyGsgQCeJlQJ -lifWJJP0osY0RQNcoQVcRkI= -=M5Dc +iEYEARECAAYFAkrDaVkACgkQEi9d9xCOQEaeSQCffdJ//p1WCHBl7VniJFbaktWN +7TUAn2JGaeQBA3NLP6XqBeJdkLyFruA6 +=4iUK -----END PGP SIGNATURE----- diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm new file mode 100644 index 0000000..51eda5d --- /dev/null +++ b/inc/Module/Install.pm @@ -0,0 +1,430 @@ +#line 1 +package Module::Install; + +# For any maintainers: +# The load order for Module::Install is a bit magic. +# It goes something like this... +# +# IF ( host has Module::Install installed, creating author mode ) { +# 1. Makefile.PL calls "use inc::Module::Install" +# 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install +# 3. The installed version of inc::Module::Install loads +# 4. inc::Module::Install calls "require Module::Install" +# 5. The ./inc/ version of Module::Install loads +# } ELSE { +# 1. Makefile.PL calls "use inc::Module::Install" +# 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install +# 3. The ./inc/ version of Module::Install loads +# } + +use 5.005; +use strict 'vars'; + +use vars qw{$VERSION $MAIN}; +BEGIN { + # All Module::Install core packages now require synchronised versions. + # This will be used to ensure we don't accidentally load old or + # different versions of modules. + # This is not enforced yet, but will be some time in the next few + # releases once we can make sure it won't clash with custom + # Module::Install extensions. + $VERSION = '0.91'; + + # Storage for the pseudo-singleton + $MAIN = undef; + + *inc::Module::Install::VERSION = *VERSION; + @inc::Module::Install::ISA = __PACKAGE__; + +} + + + + + +# Whether or not inc::Module::Install is actually loaded, the +# $INC{inc/Module/Install.pm} is what will still get set as long as +# the caller loaded module this in the documented manner. +# If not set, the caller may NOT have loaded the bundled version, and thus +# they may not have a MI version that works with the Makefile.PL. This would +# result in false errors or unexpected behaviour. And we don't want that. +my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; +unless ( $INC{$file} ) { die <<"END_DIE" } + +Please invoke ${\__PACKAGE__} with: + + use inc::${\__PACKAGE__}; + +not: + + use ${\__PACKAGE__}; + +END_DIE + + + + + +# If the script that is loading Module::Install is from the future, +# then make will detect this and cause it to re-run over and over +# again. This is bad. Rather than taking action to touch it (which +# is unreliable on some platforms and requires write permissions) +# for now we should catch this and refuse to run. +if ( -f $0 ) { + my $s = (stat($0))[9]; + + # If the modification time is only slightly in the future, + # sleep briefly to remove the problem. + my $a = $s - time; + if ( $a > 0 and $a < 5 ) { sleep 5 } + + # Too far in the future, throw an error. + my $t = time; + if ( $s > $t ) { die <<"END_DIE" } + +Your installer $0 has a modification time in the future ($s > $t). + +This is known to create infinite loops in make. + +Please correct this, then run $0 again. + +END_DIE +} + + + + + +# Build.PL was formerly supported, but no longer is due to excessive +# difficulty in implementing every single feature twice. +if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } + +Module::Install no longer supports Build.PL. + +It was impossible to maintain duel backends, and has been deprecated. + +Please remove all Build.PL files and only use the Makefile.PL installer. + +END_DIE + + + + + +# To save some more typing in Module::Install installers, every... +# use inc::Module::Install +# ...also acts as an implicit use strict. +$^H |= strict::bits(qw(refs subs vars)); + + + + + +use Cwd (); +use File::Find (); +use File::Path (); +use FindBin; + +sub autoload { + my $self = shift; + my $who = $self->_caller; + my $cwd = Cwd::cwd(); + my $sym = "${who}::AUTOLOAD"; + $sym->{$cwd} = sub { + my $pwd = Cwd::cwd(); + if ( my $code = $sym->{$pwd} ) { + # Delegate back to parent dirs + goto &$code unless $cwd eq $pwd; + } + $$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym"; + my $method = $1; + if ( uc($method) eq $method ) { + # Do nothing + return; + } elsif ( $method =~ /^_/ and $self->can($method) ) { + # Dispatch to the root M:I class + return $self->$method(@_); + } + + # Dispatch to the appropriate plugin + unshift @_, ( $self, $1 ); + goto &{$self->can('call')}; + }; +} + +sub import { + my $class = shift; + my $self = $class->new(@_); + my $who = $self->_caller; + + unless ( -f $self->{file} ) { + require "$self->{path}/$self->{dispatch}.pm"; + File::Path::mkpath("$self->{prefix}/$self->{author}"); + $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); + $self->{admin}->init; + @_ = ($class, _self => $self); + goto &{"$self->{name}::import"}; + } + + *{"${who}::AUTOLOAD"} = $self->autoload; + $self->preload; + + # Unregister loader and worker packages so subdirs can use them again + delete $INC{"$self->{file}"}; + delete $INC{"$self->{path}.pm"}; + + # Save to the singleton + $MAIN = $self; + + return 1; +} + +sub preload { + my $self = shift; + unless ( $self->{extensions} ) { + $self->load_extensions( + "$self->{prefix}/$self->{path}", $self + ); + } + + my @exts = @{$self->{extensions}}; + unless ( @exts ) { + @exts = $self->{admin}->load_all_extensions; + } + + my %seen; + foreach my $obj ( @exts ) { + while (my ($method, $glob) = each %{ref($obj) . '::'}) { + next unless $obj->can($method); + next if $method =~ /^_/; + next if $method eq uc($method); + $seen{$method}++; + } + } + + my $who = $self->_caller; + foreach my $name ( sort keys %seen ) { + *{"${who}::$name"} = sub { + ${"${who}::AUTOLOAD"} = "${who}::$name"; + goto &{"${who}::AUTOLOAD"}; + }; + } +} + +sub new { + my ($class, %args) = @_; + + # ignore the prefix on extension modules built from top level. + my $base_path = Cwd::abs_path($FindBin::Bin); + unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) { + delete $args{prefix}; + } + + return $args{_self} if $args{_self}; + + $args{dispatch} ||= 'Admin'; + $args{prefix} ||= 'inc'; + $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); + $args{bundle} ||= 'inc/BUNDLES'; + $args{base} ||= $base_path; + $class =~ s/^\Q$args{prefix}\E:://; + $args{name} ||= $class; + $args{version} ||= $class->VERSION; + unless ( $args{path} ) { + $args{path} = $args{name}; + $args{path} =~ s!::!/!g; + } + $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; + $args{wrote} = 0; + + bless( \%args, $class ); +} + +sub call { + my ($self, $method) = @_; + my $obj = $self->load($method) or return; + splice(@_, 0, 2, $obj); + goto &{$obj->can($method)}; +} + +sub load { + my ($self, $method) = @_; + + $self->load_extensions( + "$self->{prefix}/$self->{path}", $self + ) unless $self->{extensions}; + + foreach my $obj (@{$self->{extensions}}) { + return $obj if $obj->can($method); + } + + my $admin = $self->{admin} or die <<"END_DIE"; +The '$method' method does not exist in the '$self->{prefix}' path! +Please remove the '$self->{prefix}' directory and run $0 again to load it. +END_DIE + + my $obj = $admin->load($method, 1); + push @{$self->{extensions}}, $obj; + + $obj; +} + +sub load_extensions { + my ($self, $path, $top) = @_; + + unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) { + unshift @INC, $self->{prefix}; + } + + foreach my $rv ( $self->find_extensions($path) ) { + my ($file, $pkg) = @{$rv}; + next if $self->{pathnames}{$pkg}; + + local $@; + my $new = eval { require $file; $pkg->can('new') }; + unless ( $new ) { + warn $@ if $@; + next; + } + $self->{pathnames}{$pkg} = delete $INC{$file}; + push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); + } + + $self->{extensions} ||= []; +} + +sub find_extensions { + my ($self, $path) = @_; + + my @found; + File::Find::find( sub { + my $file = $File::Find::name; + return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; + my $subpath = $1; + return if lc($subpath) eq lc($self->{dispatch}); + + $file = "$self->{path}/$subpath.pm"; + my $pkg = "$self->{name}::$subpath"; + $pkg =~ s!/!::!g; + + # If we have a mixed-case package name, assume case has been preserved + # correctly. Otherwise, root through the file to locate the case-preserved + # version of the package name. + if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { + my $content = Module::Install::_read($subpath . '.pm'); + my $in_pod = 0; + foreach ( split //, $content ) { + $in_pod = 1 if /^=\w/; + $in_pod = 0 if /^=cut/; + next if ($in_pod || /^=cut/); # skip pod text + next if /^\s*#/; # and comments + if ( m/^\s*package\s+($pkg)\s*;/i ) { + $pkg = $1; + last; + } + } + } + + push @found, [ $file, $pkg ]; + }, $path ) if -d $path; + + @found; +} + + + + + +##################################################################### +# Common Utility Functions + +sub _caller { + my $depth = 0; + my $call = caller($depth); + while ( $call eq __PACKAGE__ ) { + $depth++; + $call = caller($depth); + } + return $call; +} + +sub _read { + local *FH; + if ( $] >= 5.006 ) { + open( FH, '<', $_[0] ) or die "open($_[0]): $!"; + } else { + open( FH, "< $_[0]" ) or die "open($_[0]): $!"; + } + my $string = do { local $/; <FH> }; + close FH or die "close($_[0]): $!"; + return $string; +} + +sub _readperl { + my $string = Module::Install::_read($_[0]); + $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; + $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s; + $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg; + return $string; +} + +sub _readpod { + my $string = Module::Install::_read($_[0]); + $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; + return $string if $_[0] =~ /\.pod\z/; + $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg; + $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg; + $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg; + $string =~ s/^\n+//s; + return $string; +} + +sub _write { + local *FH; + if ( $] >= 5.006 ) { + open( FH, '>', $_[0] ) or die "open($_[0]): $!"; + } else { + open( FH, "> $_[0]" ) or die "open($_[0]): $!"; + } + foreach ( 1 .. $#_ ) { + print FH $_[$_] or die "print($_[0]): $!"; + } + close FH or die "close($_[0]): $!"; +} + +# _version is for processing module versions (eg, 1.03_05) not +# Perl versions (eg, 5.8.1). +sub _version ($) { + my $s = shift || 0; + my $d =()= $s =~ /(\.)/g; + if ( $d >= 2 ) { + # Normalise multipart versions + $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg; + } + $s =~ s/^(\d+)\.?//; + my $l = $1 || 0; + my @v = map { + $_ . '0' x (3 - length $_) + } $s =~ /(\d{1,3})\D?/g; + $l = $l . '.' . join '', @v if @v; + return $l + 0; +} + +sub _cmp ($$) { + _version($_[0]) <=> _version($_[1]); +} + +# Cloned from Params::Util::_CLASS +sub _CLASS ($) { + ( + defined $_[0] + and + ! ref $_[0] + and + $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s + ) ? $_[0] : undef; +} + +1; + +# Copyright 2008 - 2009 Adam Kennedy. diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm new file mode 100644 index 0000000..60a74d2 --- /dev/null +++ b/inc/Module/Install/Base.pm @@ -0,0 +1,78 @@ +#line 1 +package Module::Install::Base; + +use strict 'vars'; +use vars qw{$VERSION}; +BEGIN { + $VERSION = '0.91'; +} + +# Suspend handler for "redefined" warnings +BEGIN { + my $w = $SIG{__WARN__}; + $SIG{__WARN__} = sub { $w }; +} + +#line 42 + +sub new { + my $class = shift; + unless ( defined &{"${class}::call"} ) { + *{"${class}::call"} = sub { shift->_top->call(@_) }; + } + unless ( defined &{"${class}::load"} ) { + *{"${class}::load"} = sub { shift->_top->load(@_) }; + } + bless { @_ }, $class; +} + +#line 61 + +sub AUTOLOAD { + local $@; + my $func = eval { shift->_top->autoload } or return; + goto &$func; +} + +#line 75 + +sub _top { + $_[0]->{_top}; +} + +#line 90 + +sub admin { + $_[0]->_top->{admin} + or + Module::Install::Base::FakeAdmin->new; +} + +#line 106 + +sub is_admin { + $_[0]->admin->VERSION; +} + +sub DESTROY {} + +package Module::Install::Base::FakeAdmin; + +my $fake; + +sub new { + $fake ||= bless(\@_, $_[0]); +} + +sub AUTOLOAD {} + +sub DESTROY {} + +# Restore warning handler +BEGIN { + $SIG{__WARN__} = $SIG{__WARN__}->(); +} + +1; + +#line 154 diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm new file mode 100644 index 0000000..e65e4f6 --- /dev/null +++ b/inc/Module/Install/Can.pm @@ -0,0 +1,81 @@ +#line 1 +package Module::Install::Can; + +use strict; +use Config (); +use File::Spec (); +use ExtUtils::MakeMaker (); +use Module::Install::Base (); + +use vars qw{$VERSION @ISA $ISCORE}; +BEGIN { + $VERSION = '0.91'; + @ISA = 'Module::Install::Base'; + $ISCORE = 1; +} + +# check if we can load some module +### Upgrade this to not have to load the module if possible +sub can_use { + my ($self, $mod, $ver) = @_; + $mod =~ s{::|\\}{/}g; + $mod .= '.pm' unless $mod =~ /\.pm$/i; + + my $pkg = $mod; + $pkg =~ s{/}{::}g; + $pkg =~ s{\.pm$}{}i; + + local $@; + eval { require $mod; $pkg->VERSION($ver || 0); 1 }; +} + +# check if we can run some command +sub can_run { + my ($self, $cmd) = @_; + + my $_cmd = $cmd; + return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); + + for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { + next if $dir eq ''; + my $abs = File::Spec->catfile($dir, $_[1]); + return $abs if (-x $abs or $abs = MM->maybe_command($abs)); + } + + return; +} + +# can we locate a (the) C compiler +sub can_cc { + my $self = shift; + my @chunks = split(/ /, $Config::Config{cc}) or return; + + # $Config{cc} may contain args; try to find out the program part + while (@chunks) { + return $self->can_run("@chunks") || (pop(@chunks), next); + } + + return; +} + +# Fix Cygwin bug on maybe_command(); +if ( $^O eq 'cygwin' ) { + require ExtUtils::MM_Cygwin; + require ExtUtils::MM_Win32; + if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { + *ExtUtils::MM_Cygwin::maybe_command = sub { + my ($self, $file) = @_; + if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { + ExtUtils::MM_Win32->maybe_command($file); + } else { + ExtUtils::MM_Unix->maybe_command($file); + } + } + } +} + +1; + +__END__ + +#line 156 diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm new file mode 100644 index 0000000..05f2079 --- /dev/null +++ b/inc/Module/Install/Fetch.pm @@ -0,0 +1,93 @@ +#line 1 +package Module::Install::Fetch; + +use strict; +use Module::Install::Base (); + +use vars qw{$VERSION @ISA $ISCORE}; +BEGIN { + $VERSION = '0.91'; + @ISA = 'Module::Install::Base'; + $ISCORE = 1; +} + +sub get_file { + my ($self, %args) = @_; + my ($scheme, $host, $path, $file) = + $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; + + if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { + $args{url} = $args{ftp_url} + or (warn("LWP support unavailable!\n"), return); + ($scheme, $host, $path, $file) = + $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; + } + + $|++; + print "Fetching '$file' from $host... "; + + unless (eval { require Socket; Socket::inet_aton($host) }) { + warn "'$host' resolve failed!\n"; + return; + } + + return unless $scheme eq 'ftp' or $scheme eq 'http'; + + require Cwd; + my $dir = Cwd::getcwd(); + chdir $args{local_dir} or return if exists $args{local_dir}; + + if (eval { require LWP::Simple; 1 }) { + LWP::Simple::mirror($args{url}, $file); + } + elsif (eval { require Net::FTP; 1 }) { eval { + # use Net::FTP to get past firewall + my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); + $ftp->login("anonymous", 'anonymous@example.com'); + $ftp->cwd($path); + $ftp->binary; + $ftp->get($file) or (warn("$!\n"), return); + $ftp->quit; + } } + elsif (my $ftp = $self->can_run('ftp')) { eval { + # no Net::FTP, fallback to ftp.exe + require FileHandle; + my $fh = FileHandle->new; + + local $SIG{CHLD} = 'IGNORE'; + unless ($fh->open("|$ftp -n")) { + warn "Couldn't open ftp: $!\n"; + chdir $dir; return; + } + + my @dialog = split(/\n/, <<"END_FTP"); +open $host +user anonymous anonymous\@example.com +cd $path +binary +get $file $file +quit +END_FTP + foreach (@dialog) { $fh->print("$_\n") } + $fh->close; + } } + else { + warn "No working 'ftp' program available!\n"; + chdir $dir; return; + } + + unless (-f $file) { + warn "Fetching failed: $@\n"; + chdir $dir; return; + } + + return if exists $args{size} and -s $file != $args{size}; + system($args{run}) if exists $args{run}; + unlink($file) if $args{remove}; + + print(((!exists $args{check_for} or -e $args{check_for}) + ? "done!" : "failed! ($!)"), "\n"); + chdir $dir; return !$?; +} + +1; diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm new file mode 100644 index 0000000..98779db --- /dev/null +++ b/inc/Module/Install/Makefile.pm @@ -0,0 +1,268 @@ +#line 1 +package Module::Install::Makefile; + +use strict 'vars'; +use ExtUtils::MakeMaker (); +use Module::Install::Base (); + +use vars qw{$VERSION @ISA $ISCORE}; +BEGIN { + $VERSION = '0.91'; + @ISA = 'Module::Install::Base'; + $ISCORE = 1; +} + +sub Makefile { $_[0] } + +my %seen = (); + +sub prompt { + shift; + + # Infinite loop protection + my @c = caller(); + if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { + die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; + } + + # In automated testing, always use defaults + if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) { + local $ENV{PERL_MM_USE_DEFAULT} = 1; + goto &ExtUtils::MakeMaker::prompt; + } else { + goto &ExtUtils::MakeMaker::prompt; + } +} + +sub makemaker_args { + my $self = shift; + my $args = ( $self->{makemaker_args} ||= {} ); + %$args = ( %$args, @_ ); + return $args; +} + +# For mm args that take multiple space-seperated args, +# append an argument to the current list. +sub makemaker_append { + my $self = sShift; + my $name = shift; + my $args = $self->makemaker_args; + $args->{name} = defined $args->{$name} + ? join( ' ', $args->{name}, @_ ) + : join( ' ', @_ ); +} + +sub build_subdirs { + my $self = shift; + my $subdirs = $self->makemaker_args->{DIR} ||= []; + for my $subdir (@_) { + push @$subdirs, $subdir; + } +} + +sub clean_files { + my $self = shift; + my $clean = $self->makemaker_args->{clean} ||= {}; + %$clean = ( + %$clean, + FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), + ); +} + +sub realclean_files { + my $self = shift; + my $realclean = $self->makemaker_args->{realclean} ||= {}; + %$realclean = ( + %$realclean, + FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), + ); +} + +sub libs { + my $self = shift; + my $libs = ref $_[0] ? shift : [ shift ]; + $self->makemaker_args( LIBS => $libs ); +} + +sub inc { + my $self = shift; + $self->makemaker_args( INC => shift ); +} + +my %test_dir = (); + +sub _wanted_t { + /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1; +} + +sub tests_recursive { + my $self = shift; + if ( $self->tests ) { + die "tests_recursive will not work if tests are already defined"; + } + my $dir = shift || 't'; + unless ( -d $dir ) { + die "tests_recursive dir '$dir' does not exist"; + } + %test_dir = (); + require File::Find; + File::Find::find( \&_wanted_t, $dir ); + $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir ); +} + +sub write { + my $self = shift; + die "&Makefile->write() takes no arguments\n" if @_; + + # Check the current Perl version + my $perl_version = $self->perl_version; + if ( $perl_version ) { + eval "use $perl_version; 1" + or die "ERROR: perl: Version $] is installed, " + . "but we need version >= $perl_version"; + } + + # Make sure we have a new enough MakeMaker + require ExtUtils::MakeMaker; + + if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { + # MakeMaker can complain about module versions that include + # an underscore, even though its own version may contain one! + # Hence the funny regexp to get rid of it. See RT #35800 + # for details. + $self->build_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ ); + $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ ); + } else { + # Allow legacy-compatibility with 5.005 by depending on the + # most recent EU:MM that supported 5.005. + $self->build_requires( 'ExtUtils::MakeMaker' => 6.42 ); + $self->configure_requires( 'ExtUtils::MakeMaker' => 6.42 ); + } + + # Generate the MakeMaker params + my $args = $self->makemaker_args; + $args->{DISTNAME} = $self->name; + $args->{NAME} = $self->module_name || $self->name; + $args->{VERSION} = $self->version; + $args->{NAME} =~ s/-/::/g; + if ( $self->tests ) { + $args->{test} = { TESTS => $self->tests }; + } + if ( $] >= 5.005 ) { + $args->{ABSTRACT} = $self->abstract; + $args->{AUTHOR} = $self->author; + } + if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) { + $args->{NO_META} = 1; + } + if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) { + $args->{SIGN} = 1; + } + unless ( $self->is_admin ) { + delete $args->{SIGN}; + } + + # Merge both kinds of requires into prereq_pm + my $prereq = ($args->{PREREQ_PM} ||= {}); + %$prereq = ( %$prereq, + map { @$_ } + map { @$_ } + grep $_, + ($self->configure_requires, $self->build_requires, $self->requires) + ); + + # Remove any reference to perl, PREREQ_PM doesn't support it + delete $args->{PREREQ_PM}->{perl}; + + # merge both kinds of requires into prereq_pm + my $subdirs = ($args->{DIR} ||= []); + if ($self->bundles) { + foreach my $bundle (@{ $self->bundles }) { + my ($file, $dir) = @$bundle; + push @$subdirs, $dir if -d $dir; + delete $prereq->{$file}; + } + } + + if ( my $perl_version = $self->perl_version ) { + eval "use $perl_version; 1" + or die "ERROR: perl: Version $] is installed, " + . "but we need version >= $perl_version"; + } + + $args->{INSTALLDIRS} = $self->installdirs; + + my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args; + + my $user_preop = delete $args{dist}->{PREOP}; + if (my $preop = $self->admin->preop($user_preop)) { + foreach my $key ( keys %$preop ) { + $args{dist}->{$key} = $preop->{$key}; + } + } + + my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); + $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); +} + +sub fix_up_makefile { + my $self = shift; + my $makefile_name = shift; + my $top_class = ref($self->_top) || ''; + my $top_version = $self->_top->VERSION || ''; + + my $preamble = $self->preamble + ? "# Preamble by $top_class $top_version\n" + . $self->preamble + : ''; + my $postamble = "# Postamble by $top_class $top_version\n" + . ($self->postamble || ''); + + local *MAKEFILE; + open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; + my $makefile = do { local $/; <MAKEFILE> }; + close MAKEFILE or die $!; + + $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; + $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; + $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; + $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; + $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; + + # Module::Install will never be used to build the Core Perl + # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks + # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist + $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; + #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; + + # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. + $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; + + # XXX - This is currently unused; not sure if it breaks other MM-users + # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; + + open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; + print MAKEFILE "$preamble$makefile$postamble" or die $!; + close MAKEFILE or die $!; + + 1; +} + +sub preamble { + my ($self, $text) = @_; + $self->{preamble} = $text . $self->{preamble} if defined $text; + $self->{preamble}; +} + +sub postamble { + my ($self, $text) = @_; + $self->{postamble} ||= $self->admin->postamble; + $self->{postamble} .= $text if defined $text; + $self->{postamble} +} + +1; + +__END__ + +#line 394 diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm new file mode 100644 index 0000000..653193d --- /dev/null +++ b/inc/Module/Install/Metadata.pm @@ -0,0 +1,624 @@ +#line 1 +package Module::Install::Metadata; + +use strict 'vars'; +use Module::Install::Base (); + +use vars qw{$VERSION @ISA $ISCORE}; +BEGIN { + $VERSION = '0.91'; + @ISA = 'Module::Install::Base'; + $ISCORE = 1; +} + +my @boolean_keys = qw{ + sign +}; + +my @scalar_keys = qw{ + name + module_name + abstract + author + version + distribution_type + tests + installdirs +}; + +my @tuple_keys = qw{ + configure_requires + build_requires + requires + recommends + bundles + resources +}; + +my @resource_keys = qw{ + homepage + bugtracker + repository +}; + +my @array_keys = qw{ + keywords +}; + +sub Meta { shift } +sub Meta_BooleanKeys { @boolean_keys } +sub Meta_ScalarKeys { @scalar_keys } +sub Meta_TupleKeys { @tuple_keys } +sub Meta_ResourceKeys { @resource_keys } +sub Meta_ArrayKeys { @array_keys } + +foreach my $key ( @boolean_keys ) { + *$key = sub { + my $self = shift; + if ( defined wantarray and not @_ ) { + return $self->{values}->{$key}; + } + $self->{values}->{$key} = ( @_ ? $_[0] : 1 ); + return $self; + }; +} + +foreach my $key ( @scalar_keys ) { + *$key = sub { + my $self = shift; + return $self->{values}->{$key} if defined wantarray and !@_; + $self->{values}->{$key} = shift; + return $self; + }; +} + +foreach my $key ( @array_keys ) { + *$key = sub { + my $self = shift; + return $self->{values}->{$key} if defined wantarray and !@_; + $self->{values}->{$key} ||= []; + push @{$self->{values}->{$key}}, @_; + return $self; + }; +} + +foreach my $key ( @resource_keys ) { + *$key = sub { + my $self = shift; + unless ( @_ ) { + return () unless $self->{values}->{resources}; + return map { $_->[1] } + grep { $_->[0] eq $key } + @{ $self->{values}->{resources} }; + } + return $self->{values}->{resources}->{$key} unless @_; + my $uri = shift or die( + "Did not provide a value to $key()" + ); + $self->resources( $key => $uri ); + return 1; + }; +} + +foreach my $key ( grep { $_ ne "resources" } @tuple_keys) { + *$key = sub { + my $self = shift; + return $self->{values}->{$key} unless @_; + my @added; + while ( @_ ) { + my $module = shift or last; + my $version = shift || 0; + push @added, [ $module, $version ]; + } + push @{ $self->{values}->{$key} }, @added; + return map {@$_} @added; + }; +} + +# Resource handling +my %lc_resource = map { $_ => 1 } qw{ + homepage + license + bugtracker + repository +}; + +sub resources { + my $self = shift; + while ( @_ ) { + my $name = shift or last; + my $value = shift or next; + if ( $name eq lc $name and ! $lc_resource{$name} ) { + die("Unsupported reserved lowercase resource '$name'"); + } + $self->{values}->{resources} ||= []; + push @{ $self->{values}->{resources} }, [ $name, $value ]; + } + $self->{values}->{resources}; +} + +# Aliases for build_requires that will have alternative +# meanings in some future version of META.yml. +sub test_requires { shift->build_requires(@_) } +sub install_requires { shift->build_requires(@_) } + +# Aliases for installdirs options +sub install_as_core { $_[0]->installdirs('perl') } +sub install_as_cpan { $_[0]->installdirs('site') } +sub install_as_site { $_[0]->installdirs('site') } +sub install_as_vendor { $_[0]->installdirs('vendor') } + +sub dynamic_config { + my $self = shift; + unless ( @_ ) { + warn "You MUST provide an explicit true/false value to dynamic_config\n"; + return $self; + } + $self->{values}->{dynamic_config} = $_[0] ? 1 : 0; + return 1; +} + +sub perl_version { + my $self = shift; + return $self->{values}->{perl_version} unless @_; + my $version = shift or die( + "Did not provide a value to perl_version()" + ); + + # Normalize the version + $version = $self->_perl_version($version); + + # We don't support the reall old versions + unless ( $version >= 5.005 ) { + die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; + } + + $self->{values}->{perl_version} = $version; +} + +#Stolen from M::B +my %license_urls = ( + perl => 'http://dev.perl.org/licenses/', + apache => 'http://apache.org/licenses/LICENSE-2.0', + artistic => 'http://opensource.org/licenses/artistic-license.php', + artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', + lgpl => 'http://opensource.org/licenses/lgpl-license.php', + lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', + lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', + bsd => 'http://opensource.org/licenses/bsd-license.php', + gpl => 'http://opensource.org/licenses/gpl-license.php', + gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', + gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', + mit => 'http://opensource.org/licenses/mit-license.php', + mozilla => 'http://opensource.org/licenses/mozilla1.1.php', + open_source => undef, + unrestricted => undef, + restrictive => undef, + unknown => undef, +); + +sub license { + my $self = shift; + return $self->{values}->{license} unless @_; + my $license = shift or die( + 'Did not provide a value to license()' + ); + $self->{values}->{license} = $license; + + # Automatically fill in license URLs + if ( $license_urls{$license} ) { + $self->resources( license => $license_urls{$license} ); + } + + return 1; +} + +sub all_from { + my ( $self, $file ) = @_; + + unless ( defined($file) ) { + my $name = $self->name or die( + "all_from called with no args without setting name() first" + ); + $file = join('/', 'lib', split(/-/, $name)) . '.pm'; + $file =~ s{.*/}{} unless -e $file; + unless ( -e $file ) { + die("all_from cannot find $file from $name"); + } + } + unless ( -f $file ) { + die("The path '$file' does not exist, or is not a file"); + } + + # Some methods pull from POD instead of code. + # If there is a matching .pod, use that instead + my $pod = $file; + $pod =~ s/\.pm$/.pod/i; + $pod = $file unless -e $pod; + + # Pull the different values + $self->name_from($file) unless $self->name; + $self->version_from($file) unless $self->version; + $self->perl_version_from($file) unless $self->perl_version; + $self->author_from($pod) unless $self->author; + $self->license_from($pod) unless $self->license; + $self->abstract_from($pod) unless $self->abstract; + + return 1; +} + +sub provides { + my $self = shift; + my $provides = ( $self->{values}->{provides} ||= {} ); + %$provides = (%$provides, @_) if @_; + return $provides; +} + +sub auto_provides { + my $self = shift; + return $self unless $self->is_admin; + unless (-e 'MANIFEST') { + warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; + return $self; + } + # Avoid spurious warnings as we are not checking manifest here. + local $SIG{__WARN__} = sub {1}; + require ExtUtils::Manifest; + local *ExtUtils::Manifest::manicheck = sub { return }; + + require Module::Build; + my $build = Module::Build->new( + dist_name => $self->name, + dist_version => $self->version, + license => $self->license, + ); + $self->provides( %{ $build->find_dist_packages || {} } ); +} + +sub feature { + my $self = shift; + my $name = shift; + my $features = ( $self->{values}->{features} ||= [] ); + my $mods; + + if ( @_ == 1 and ref( $_[0] ) ) { + # The user used ->feature like ->features by passing in the second + # argument as a reference. Accomodate for that. + $mods = $_[0]; + } else { + $mods = \@_; + } + + my $count = 0; + push @$features, ( + $name => [ + map { + ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ + } @$mods + ] + ); + + return @$features; +} + +sub features { + my $self = shift; + while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { + $self->feature( $name, @$mods ); + } + return $self->{values}->{features} + ? @{ $self->{values}->{features} } + : (); +} + +sub no_index { + my $self = shift; + my $type = shift; + push @{ $self->{values}->{no_index}->{$type} }, @_ if $type; + return $self->{values}->{no_index}; +} + +sub read { + my $self = shift; + $self->include_deps( 'YAML::Tiny', 0 ); + + require YAML::Tiny; + my $data = YAML::Tiny::LoadFile('META.yml'); + + # Call methods explicitly in case user has already set some values. + while ( my ( $key, $value ) = each %$data ) { + next unless $self->can($key); + if ( ref $value eq 'HASH' ) { + while ( my ( $module, $version ) = each %$value ) { + $self->can($key)->($self, $module => $version ); + } + } else { + $self->can($key)->($self, $value); + } + } + return $self; +} + +sub write { + my $self = shift; + return $self unless $self->is_admin; + $self->admin->write_meta; + return $self; +} + +sub version_from { + require ExtUtils::MM_Unix; + my ( $self, $file ) = @_; + $self->version( ExtUtils::MM_Unix->parse_version($file) ); +} + +sub abstract_from { + require ExtUtils::MM_Unix; + my ( $self, $file ) = @_; + $self->abstract( + bless( + { DISTNAME => $self->name }, + 'ExtUtils::MM_Unix' + )->parse_abstract($file) + ); +} + +# Add both distribution and module name +sub name_from { + my ($self, $file) = @_; + if ( + Module::Install::_read($file) =~ m/ + ^ \s* + package \s* + ([\w:]+) + \s* ; + /ixms + ) { + my ($name, $module_name) = ($1, $1); + $name =~ s{::}{-}g; + $self->name($name); + unless ( $self->module_name ) { + $self->module_name($module_name); + } + } else { + die("Cannot determine name from $file\n"); + } +} + +sub perl_version_from { + my $self = shift; + if ( + Module::Install::_read($_[0]) =~ m/ + ^ + (?:use|require) \s* + v? + ([\d_\.]+) + \s* ; + /ixms + ) { + my $perl_version = $1; + $perl_version =~ s{_}{}g; + $self->perl_version($perl_version); + } else { + warn "Cannot determine perl version info from $_[0]\n"; + return; + } +} + +sub author_from { + my $self = shift; + my $content = Module::Install::_read($_[0]); + if ($content =~ m/ + =head \d \s+ (?:authors?)\b \s* + ([^\n]*) + | + =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* + .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* + ([^\n]*) + /ixms) { + my $author = $1 || $2; + $author =~ s{E<lt>}{<}g; + $author =~ s{E<gt>}{>}g; + $self->author($author); + } else { + warn "Cannot determine author info from $_[0]\n"; + } +} + +sub license_from { + my $self = shift; + if ( + Module::Install::_read($_[0]) =~ m/ + ( + =head \d \s+ + (?:licen[cs]e|licensing|copyright|legal)\b + .*? + ) + (=head\\d.*|=cut.*|) + \z + /ixms ) { + my $license_text = $1; + my @phrases = ( + 'under the same (?:terms|license) as (?:perl|the perl programming language) itself' => 'perl', 1, + 'GNU general public license' => 'gpl', 1, + 'GNU public license' => 'gpl', 1, + 'GNU lesser general public license' => 'lgpl', 1, + 'GNU lesser public license' => 'lgpl', 1, + 'GNU library general public license' => 'lgpl', 1, + 'GNU library public license' => 'lgpl', 1, + 'BSD license' => 'bsd', 1, + 'Artistic license' => 'artistic', 1, + 'GPL' => 'gpl', 1, + 'LGPL' => 'lgpl', 1, + 'BSD' => 'bsd', 1, + 'Artistic' => 'artistic', 1, + 'MIT' => 'mit', 1, + 'proprietary' => 'proprietary', 0, + ); + while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { + $pattern =~ s{\s+}{\\s+}g; + if ( $license_text =~ /\b$pattern\b/i ) { + $self->license($license); + return 1; + } + } + } + + warn "Cannot determine license info from $_[0]\n"; + return 'unknown'; +} + +sub _extract_bugtracker { + my @links = $_[0] =~ m#L<(\Qhttp://rt.cpan.org/\E[^>]+)>#g; + my %links; + @links{@links}=(); + @links=keys %links; + return @links; +} + +sub bugtracker_from { + my $self = shift; + my $content = Module::Install::_read($_[0]); + my @links = _extract_bugtracker($content); + unless ( @links ) { + warn "Cannot determine bugtracker info from $_[0]\n"; + return 0; + } + if ( @links > 1 ) { + warn "Found more than on rt.cpan.org link in $_[0]\n"; + return 0; + } + + # Set the bugtracker + bugtracker( $links[0] ); + return 1; +} + +sub requires_from { + my $self = shift; + my $content = Module::Install::_readperl($_[0]); + my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; + while ( @requires ) { + my $module = shift @requires; + my $version = shift @requires; + $self->requires( $module => $version ); + } +} + +sub test_requires_from { + my $self = shift; + my $content = Module::Install::_readperl($_[0]); + my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; + while ( @requires ) { + my $module = shift @requires; + my $version = shift @requires; + $self->test_requires( $module => $version ); + } +} + +# Convert triple-part versions (eg, 5.6.1 or 5.8.9) to +# numbers (eg, 5.006001 or 5.008009). +# Also, convert double-part versions (eg, 5.8) +sub _perl_version { + my $v = $_[-1]; + $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e; + $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e; + $v =~ s/(\.\d\d\d)000$/$1/; + $v =~ s/_.+$//; + if ( ref($v) ) { + # Numify + $v = $v + 0; + } + return $v; +} + + + + + +###################################################################### +# MYMETA Support + +sub WriteMyMeta { + die "WriteMyMeta has been deprecated"; +} + +sub write_mymeta_yaml { + my $self = shift; + + # We need YAML::Tiny to write the MYMETA.yml file + unless ( eval { require YAML::Tiny; 1; } ) { + return 1; + } + + # Generate the data + my $meta = $self->_write_mymeta_data or return 1; + + # Save as the MYMETA.yml file + print "Writing MYMETA.yml\n"; + YAML::Tiny::DumpFile('MYMETA.yml', $meta); +} + +sub write_mymeta_json { + my $self = shift; + + # We need JSON to write the MYMETA.json file + unless ( eval { require JSON; 1; } ) { + return 1; + } + + # Generate the data + my $meta = $self->_write_mymeta_data or return 1; + + # Save as the MYMETA.yml file + print "Writing MYMETA.json\n"; + Module::Install::_write( + 'MYMETA.json', + JSON->new->pretty(1)->canonical->encode($meta), + ); +} + +sub _write_mymeta_data { + my $self = shift; + + # If there's no existing META.yml there is nothing we can do + return undef unless -f 'META.yml'; + + # We need Parse::CPAN::Meta to load the file + unless ( eval { require Parse::CPAN::Meta; 1; } ) { + return undef; + } + + # Merge the perl version into the dependencies + my $val = $self->Meta->{values}; + my $perl = delete $val->{perl_version}; + if ( $perl ) { + $val->{requires} ||= []; + my $requires = $val->{requires}; + + # Canonize to three-dot version after Perl 5.6 + if ( $perl >= 5.006 ) { + $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e + } + unshift @$requires, [ perl => $perl ]; + } + + # Load the advisory META.yml file + my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); + my $meta = $yaml[0]; + + # Overwrite the non-configure dependency hashs + delete $meta->{requires}; + delete $meta->{build_requires}; + delete $meta->{recommends}; + if ( exists $val->{requires} ) { + $meta->{requires} = { map { @$_ } @{ $val->{requires} } }; + } + if ( exists $val->{build_requires} ) { + $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } }; + } + + return $meta; +} + +1; diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm new file mode 100644 index 0000000..f2f99df --- /dev/null +++ b/inc/Module/Install/Win32.pm @@ -0,0 +1,64 @@ +#line 1 +package Module::Install::Win32; + +use strict; +use Module::Install::Base (); + +use vars qw{$VERSION @ISA $ISCORE}; +BEGIN { + $VERSION = '0.91'; + @ISA = 'Module::Install::Base'; + $ISCORE = 1; +} + +# determine if the user needs nmake, and download it if needed +sub check_nmake { + my $self = shift; + $self->load('can_run'); + $self->load('get_file'); + + require Config; + return unless ( + $^O eq 'MSWin32' and + $Config::Config{make} and + $Config::Config{make} =~ /^nmake\b/i and + ! $self->can_run('nmake') + ); + + print "The required 'nmake' executable not found, fetching it...\n"; + + require File::Basename; + my $rv = $self->get_file( + url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', + ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', + local_dir => File::Basename::dirname($^X), + size => 51928, + run => 'Nmake15.exe /o > nul', + check_for => 'Nmake.exe', + remove => 1, + ); + + die <<'END_MESSAGE' unless $rv; + +------------------------------------------------------------------------------- + +Since you are using Microsoft Windows, you will need the 'nmake' utility +before installation. It's available at: + + http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe + or + ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe + +Please download the file manually, save it to a directory in %PATH% (e.g. +C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to +that directory, and run "Nmake15.exe" from there; that will create the +'nmake.exe' file needed by this module. + +You may then resume the installation process described in README. + +------------------------------------------------------------------------------- +END_MESSAGE + +} + +1; diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm new file mode 100644 index 0000000..12471e5 --- /dev/null +++ b/inc/Module/Install/WriteAll.pm @@ -0,0 +1,60 @@ +#line 1 +package Module::Install::WriteAll; + +use strict; +use Module::Install::Base (); + +use vars qw{$VERSION @ISA $ISCORE}; +BEGIN { + $VERSION = '0.91';; + @ISA = qw{Module::Install::Base}; + $ISCORE = 1; +} + +sub WriteAll { + my $self = shift; + my %args = ( + meta => 1, + sign => 0, + inline => 0, + check_nmake => 1, + @_, + ); + + $self->sign(1) if $args{sign}; + $self->admin->WriteAll(%args) if $self->is_admin; + + $self->check_nmake if $args{check_nmake}; + unless ( $self->makemaker_args->{PL_FILES} ) { + $self->makemaker_args( PL_FILES => {} ); + } + + # Until ExtUtils::MakeMaker support MYMETA.yml, make sure + # we clean it up properly ourself. + $self->realclean_files('MYMETA.yml'); + + if ( $args{inline} ) { + $self->Inline->write; + } else { + $self->Makefile->write; + } + + # The Makefile write process adds a couple of dependencies, + # so write the META.yml files after the Makefile. + if ( $args{meta} ) { + $self->Meta->write; + } + + # Experimental support for MYMETA + if ( $ENV{X_MYMETA} ) { + if ( $ENV{X_MYMETA} eq 'JSON' ) { + $self->Meta->write_mymeta_json; + } else { + $self->Meta->write_mymeta_yaml; + } + } + + return 1; +} + +1; diff --git a/lib/GnuPG/Fingerprint.pm b/lib/GnuPG/Fingerprint.pm index 75f9170..1335d30 100644 --- a/lib/GnuPG/Fingerprint.pm +++ b/lib/GnuPG/Fingerprint.pm @@ -14,12 +14,13 @@ # package GnuPG::Fingerprint; +use Any::Moose; +with qw(GnuPG::HashInit); -use strict; - -use Class::MethodMaker - get_set => [ qw( as_hex_string ) ], - new_hash_init => 'new'; +has as_hex_string => ( + isa => 'Any', + is => 'rw', +); # DEPRECATED sub hex_data @@ -29,6 +30,8 @@ sub hex_data return $self->as_hex_string(); } +__PACKAGE__->meta->make_immutable; + 1; __END__ @@ -56,23 +59,14 @@ objects, and are not created on their own. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members. =item hash_init( I<%args> ). -This method works as described in L<Class::MethodMaker/"new_hash_init">. - =back =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -or L<Class::MethodMaker/"object">. -Please read there for more information. - =over 4 =item as_hex_string @@ -85,6 +79,5 @@ in string format. =head1 SEE ALSO L<GnuPG::Key>, -L<Class::MethodMaker> =cut diff --git a/lib/GnuPG/Handles.pm b/lib/GnuPG/Handles.pm index 975eba2..fabf31c 100644 --- a/lib/GnuPG/Handles.pm +++ b/lib/GnuPG/Handles.pm @@ -13,37 +13,54 @@ # $Id: Handles.pm,v 1.8 2001/12/09 02:24:10 ftobin Exp $ # - package GnuPG::Handles; +use Any::Moose; +with qw(GnuPG::HashInit); + +use constant HANDLES => qw( + stdin + stdout + stderr + status + logger + passphrase + command +); + +has "$_" => ( + isa => 'Any', + is => 'rw', + clearer => 'clear_' . $_, +) for HANDLES; + +has _options => ( + isa => 'HashRef', + is => 'rw', + lazy_build => 1, +); + +sub options { + my $self = shift; + my $key = shift; + + return $self->_options->{$key}; +} -use strict; - -use constant HANDLES => qw( stdin stdout stderr - status logger passphrase - command - ); - -use Class::MethodMaker - get_set => [ HANDLES ], - hash => [ qw( options ) ], - new_with_init => 'new', - new_hash_init => 'hash_init'; +sub _build__options { {} } +sub BUILD { + my ( $self, $args ) = @_; -sub init -{ - my ( $self, %args ) = @_; # This is done for the user's convenience so that they don't # have to worry about undefined hashrefs - foreach my $handle ( HANDLES ) { $self->options( $handle, {} ) } - $self->hash_init( %args ); + $self->_options->{$_} = {} for HANDLES; + $self->hash_init(%$args); } - +__PACKAGE__->meta->make_immutable; 1; - =head1 NAME GnuPG::Handles - GnuPG handles bundle @@ -84,23 +101,15 @@ communicate with GnuPG. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members. =item hash_init( I<%args> ). -This method works as described in L<Class::MethodMaker/"new_hash_init">. =back =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -or L<Class::MethodMaker/"object">. -Please read there for more information. - =over 4 =item stdin @@ -173,6 +182,5 @@ an already-opened file. =head1 SEE ALSO L<GnuPG::Interface>, -L<Class::MethodMaker> =cut diff --git a/lib/GnuPG/HashInit.pm b/lib/GnuPG/HashInit.pm new file mode 100644 index 0000000..9daa6a9 --- /dev/null +++ b/lib/GnuPG/HashInit.pm @@ -0,0 +1,12 @@ +package GnuPG::HashInit; +use Any::Moose 'Role'; + +sub hash_init { + my ($self, %args) = @_; + while ( my ( $method, $value ) = each %args ) { + $self->$method($value); + } +} + +1; +__END__ diff --git a/lib/GnuPG/Interface.pm b/lib/GnuPG/Interface.pm index c4afcaa..15588b4 100644 --- a/lib/GnuPG/Interface.pm +++ b/lib/GnuPG/Interface.pm @@ -12,745 +12,707 @@ # package GnuPG::Interface; +use Any::Moose; +with qw(GnuPG::HashInit); -use strict; use English qw( -no_match_vars ); use Carp; use Fcntl; use vars qw( $VERSION ); use Fatal qw( open close pipe fcntl ); -use AutoLoader 'AUTOLOAD'; use Class::Struct; use IO::Handle; use GnuPG::Options; use GnuPG::Handles; -$VERSION = '0.36'; +$VERSION = '0.42'; -use Class::MethodMaker - get_set => [ qw( call passphrase ) ], - object => [ qw( GnuPG::Options options ) ], - new_with_init => 'new', - new_hash_init => 'hash_init'; +has $_ => ( + isa => 'Any', + is => 'rw', + clearer => 'clear_' . $_, +) for qw(call passphrase); -# deprecated! -sub gnupg_call -{ - my ( $self, $v ) = @_; - $self->call( $v ) if defined $v; - return $self->call(); -} +has options => ( + isa => 'GnuPG::Options', + is => 'rw', + lazy_build => 1, +); +sub _build_options { GnuPG::Options->new() } -sub init( $% ) -{ - my ( $self, %args ) = @_; - - $self->hash_init( call => 'gpg' ), - $self->hash_init( %args ); -} +# deprecated! +sub gnupg_call { shift->call(@_); } +sub BUILD { + my ( $self, $args ) = @_; -struct ( fh_setup => { parent_end => '$', child_end => '$', - direct => '$', is_std => '$', - parent_is_source => '$', name_shows_dup => '$', - } - ); + $self->hash_init( call => 'gpg' ); + $self->hash_init(%$args); +} -1; +struct( + fh_setup => { + parent_end => '$', child_end => '$', + direct => '$', is_std => '$', + parent_is_source => '$', name_shows_dup => '$', + } +); ################################################################# # real worker functions - # This function does any 'extra' stuff that the user might # not want to handle himself, such as passing in the passphrase -sub wrap_call( $% ) -{ +sub wrap_call( $% ) { my ( $self, %args ) = @_; - + my $handles = $args{handles} - or croak 'error: no handles defined'; - - $handles->stdin( '<&STDIN' ) unless $handles->stdin(); - $handles->stdout( '>&STDOUT' ) unless $handles->stdout(); - $handles->stderr( '>&STDERR' ) unless $handles->stderr(); - + or croak 'error: no handles defined'; + + $handles->stdin('<&STDIN') unless $handles->stdin(); + $handles->stdout('>&STDOUT') unless $handles->stdout(); + $handles->stderr('>&STDERR') unless $handles->stderr(); + # so call me sexist; English just doen't cope well - my $needs_passphrase_handled_for_him = - ( $self->passphrase() and not $handles->passphrase() ) - ? 1 : 0; - - if ( $needs_passphrase_handled_for_him ) - { - $handles->passphrase( IO::Handle->new() ); - } - - my $pid = $self->fork_attach_exec( %args ); - - if ( $needs_passphrase_handled_for_him ) - { - my $passphrase_handle = $handles->passphrase(); - print $passphrase_handle $self->passphrase(); - close $passphrase_handle; - - # We put this in in case the user wants to re-use this object - $handles->clear_passphrase(); + my $needs_passphrase_handled_for_him + = ( $self->passphrase() and not $handles->passphrase() ) ? 1 : 0; + + if ($needs_passphrase_handled_for_him) { + $handles->passphrase( IO::Handle->new() ); } - - return $pid; -} + my $pid = $self->fork_attach_exec(%args); + if ($needs_passphrase_handled_for_him) { + my $passphrase_handle = $handles->passphrase(); + print $passphrase_handle $self->passphrase(); + close $passphrase_handle; + # We put this in in case the user wants to re-use this object + $handles->clear_passphrase(); + } + + return $pid; +} # does does command-line creation, forking, and execcing # the reasing cli creation is done here is because we should # fork before finding the fd's for stuff like --status-fd -sub fork_attach_exec( $% ) -{ +sub fork_attach_exec( $% ) { my ( $self, %args ) = @_; - + my $handles = $args{handles} or croak 'no GnuPG::Handles passed'; - + # deprecation support $args{commands} ||= $args{gnupg_commands}; - - my @commands = ref $args{commands} - ? @{ $args{commands} } : ( $args{commands} ) - or croak "no gnupg commands passed"; - + + my @commands + = ref $args{commands} ? @{ $args{commands} } : ( $args{commands} ) + or croak "no gnupg commands passed"; + # deprecation support $args{command_args} ||= $args{gnupg_command_args}; - - my @command_args = ref $args{command_args} - ? @{ $args{command_args} } : ( $args{command_args } || () ); - + + my @command_args + = ref $args{command_args} + ? @{ $args{command_args} } + : ( $args{command_args} || () ); + my %fhs; - foreach my $fh_name ( qw( stdin stdout stderr status - logger passphrase command - ) - ) - { - my $fh = $handles->$fh_name() or next; - $fhs{$fh_name} = fh_setup->new(); - $fhs{$fh_name}->parent_end( $fh ); + foreach my $fh_name ( + qw( stdin stdout stderr status + logger passphrase command + ) + ) { + my $fh = $handles->$fh_name() or next; + $fhs{$fh_name} = fh_setup->new(); + $fhs{$fh_name}->parent_end($fh); } - - foreach my $fh_name ( qw( stdin stdout stderr ) ) - { - $fhs{$fh_name}->is_std( 1 ); + + foreach my $fh_name (qw( stdin stdout stderr )) { + $fhs{$fh_name}->is_std(1); } - - foreach my $fh_name ( qw( stdin passphrase command ) ) - { - my $entry = $fhs{$fh_name} or next; - $entry->parent_is_source( 1 ); + + foreach my $fh_name (qw( stdin passphrase command )) { + my $entry = $fhs{$fh_name} or next; + $entry->parent_is_source(1); } - + # Below is code derived heavily from # Marc Horowitz's IPC::Open3, a base Perl module - foreach my $fh_name ( keys %fhs ) - { - my $entry = $fhs{$fh_name}; - - my $parent_end = $entry->parent_end(); - my $name_shows_dup = ( $parent_end =~ s/^[<>]&// ); - $entry->parent_end( $parent_end ); - - $entry->name_shows_dup( $name_shows_dup ); - - $entry->direct( $name_shows_dup - || $handles->options( $fh_name )->{direct} - || 0 - ); + foreach my $fh_name ( keys %fhs ) { + my $entry = $fhs{$fh_name}; + + my $parent_end = $entry->parent_end(); + my $name_shows_dup = ( $parent_end =~ s/^[<>]&// ); + $entry->parent_end($parent_end); + + $entry->name_shows_dup($name_shows_dup); + + $entry->direct( $name_shows_dup + || $handles->options($fh_name)->{direct} + || 0 ); } - - foreach my $fh_name ( keys %fhs ) - { - $fhs{$fh_name}->child_end( IO::Handle->new() ); + + foreach my $fh_name ( keys %fhs ) { + $fhs{$fh_name}->child_end( IO::Handle->new() ); } - - foreach my $fh_name ( keys %fhs ) - { - my $entry = $fhs{$fh_name}; - next if $entry->direct(); - - my $reader_end; - my $writer_end; - if ( $entry->parent_is_source() ) - { - $reader_end = $entry->child_end(); - $writer_end = $entry->parent_end(); - } - else - { - $reader_end = $entry->parent_end(); - $writer_end = $entry->child_end(); - } - - pipe $reader_end, $writer_end; + + foreach my $fh_name ( keys %fhs ) { + my $entry = $fhs{$fh_name}; + next if $entry->direct(); + + my $reader_end; + my $writer_end; + if ( $entry->parent_is_source() ) { + $reader_end = $entry->child_end(); + $writer_end = $entry->parent_end(); + } + else { + $reader_end = $entry->parent_end(); + $writer_end = $entry->child_end(); + } + + pipe $reader_end, $writer_end; } - + my $pid = fork; - + die "fork failed: $ERRNO" unless defined $pid; - - if ( $pid == 0 ) # child + + if ( $pid == 0 ) # child { - # these are for safety later to help lessen autovifying, - # speed things up, and make the code smaller - my $stdin = $fhs{stdin}; - my $stdout = $fhs{stdout}; - my $stderr = $fhs{stderr}; - - # Paul Walmsley says: - # Perl 5.6's POSIX.pm has a typo in it that prevents us from - # importing STDERR_FILENO. So we resort to requiring it. - require POSIX; - - my $standard_out = IO::Handle->new_from_fd( &POSIX::STDOUT_FILENO, 'w' ); - my $standard_in = IO::Handle->new_from_fd( &POSIX::STDIN_FILENO, 'r' ); - - # Paul Walmsley says: - # this mess is due to a typo in POSIX.pm on Perl 5.6 - my $stderr_fd = eval { &POSIX::STDERR_FILENO }; - $stderr_fd = 2 unless defined $stderr_fd; - my $standard_err = IO::Handle->new_from_fd ($stderr_fd, 'w'); - - # If she wants to dup the kid's stderr onto her stdout I need to - # save a copy of her stdout before I put something else there. - if ( $stdout->parent_end() ne $stderr->parent_end() - and $stderr->direct() - and my_fileno( $stderr->parent_end() ) == my_fileno( $standard_out ) ) - { - my $tmp = IO::Handle->new(); - open $tmp, '>&' . my_fileno( $stderr->parent_end() ); - $stderr->parent_end( $tmp ); - } - - if ( $stdin->direct() ) - { - open $standard_in, '<&' . my_fileno( $stdin->parent_end() ) - unless - my_fileno( $standard_in ) == my_fileno( $stdin->parent_end() ); - } - else - { - close $stdin->parent_end(); - open $standard_in, '<&=' . my_fileno( $stdin->child_end() ); - } - - if ( $stdout->direct() ) - { - open $standard_out, '>&' . my_fileno( $stdout->parent_end() ) - unless - my_fileno( $standard_out ) == my_fileno( $stdout->parent_end() ); - } - else - { - close $stdout->parent_end(); - open $standard_out, '>&=' . my_fileno( $stdout->child_end() ); - } - - if ( $stdout->parent_end() ne $stderr->parent_end() ) - { - # I have to use a fileno here because in this one case - # I'm doing a dup but the filehandle might be a reference - # (from the special case above). - if ( $stderr->direct() ) - { - open $standard_err, '>&' . my_fileno( $stderr->parent_end() ) - unless - my_fileno( $standard_err ) - == my_fileno( $stderr->parent_end() ); - } - else - { - close $stderr->parent_end(); - open $standard_err, '>&=' . my_fileno( $stderr->child_end() ); - } - } - else - { - open $standard_err, '>&STDOUT' - unless my_fileno( $standard_err ) == my_fileno( $standard_out ); - } - - foreach my $fh_name ( keys %fhs ) - { - my $entry = $fhs{$fh_name}; - next if $entry->is_std(); - - my $parent_end = $entry->parent_end(); - my $child_end = $entry->child_end(); - - if ( $entry->direct() ) - { - if ( $entry->name_shows_dup() ) - { - my $open_prefix = $entry->parent_is_source() ? '<&' : '>&'; - open $child_end, $open_prefix . $parent_end; - } - else - { - $child_end = $parent_end; - $entry->child_end( $child_end ); - } - } - else - { - close $parent_end; - } - - # we want these fh's to stay open after the exec - fcntl $child_end, F_SETFD, 0; - - # now set the options for the call to GnuPG - my $fileno = my_fileno( $child_end ); - my $option = $fh_name . '_fd'; - $self->options->$option( $fileno ); - } - - - my @command = ( $self->call(), $self->options->get_args(), - @commands, @command_args ); - - exec @command or die "exec() error: $ERRNO"; + + # these are for safety later to help lessen autovifying, + # speed things up, and make the code smaller + my $stdin = $fhs{stdin}; + my $stdout = $fhs{stdout}; + my $stderr = $fhs{stderr}; + + # Paul Walmsley says: + # Perl 5.6's POSIX.pm has a typo in it that prevents us from + # importing STDERR_FILENO. So we resort to requiring it. + require POSIX; + + my $standard_out + = IO::Handle->new_from_fd( &POSIX::STDOUT_FILENO, 'w' ); + my $standard_in + = IO::Handle->new_from_fd( &POSIX::STDIN_FILENO, 'r' ); + + # Paul Walmsley says: + # this mess is due to a typo in POSIX.pm on Perl 5.6 + my $stderr_fd = eval {&POSIX::STDERR_FILENO}; + $stderr_fd = 2 unless defined $stderr_fd; + my $standard_err = IO::Handle->new_from_fd( $stderr_fd, 'w' ); + + # If she wants to dup the kid's stderr onto her stdout I need to + # save a copy of her stdout before I put something else there. + if ( $stdout->parent_end() ne $stderr->parent_end() + and $stderr->direct() + and my_fileno( $stderr->parent_end() ) + == my_fileno($standard_out) ) { + my $tmp = IO::Handle->new(); + open $tmp, '>&' . my_fileno( $stderr->parent_end() ); + $stderr->parent_end($tmp); + } + + if ( $stdin->direct() ) { + open $standard_in, '<&' . my_fileno( $stdin->parent_end() ) + unless my_fileno($standard_in) + == my_fileno( $stdin->parent_end() ); + } + else { + close $stdin->parent_end(); + open $standard_in, '<&=' . my_fileno( $stdin->child_end() ); + } + + if ( $stdout->direct() ) { + open $standard_out, '>&' . my_fileno( $stdout->parent_end() ) + unless my_fileno($standard_out) + == my_fileno( $stdout->parent_end() ); + } + else { + close $stdout->parent_end(); + open $standard_out, '>&=' . my_fileno( $stdout->child_end() ); + } + + if ( $stdout->parent_end() ne $stderr->parent_end() ) { + + # I have to use a fileno here because in this one case + # I'm doing a dup but the filehandle might be a reference + # (from the special case above). + if ( $stderr->direct() ) { + open $standard_err, '>&' . my_fileno( $stderr->parent_end() ) + unless my_fileno($standard_err) + == my_fileno( $stderr->parent_end() ); + } + else { + close $stderr->parent_end(); + open $standard_err, '>&=' . my_fileno( $stderr->child_end() ); + } + } + else { + open $standard_err, '>&STDOUT' + unless my_fileno($standard_err) == my_fileno($standard_out); + } + + foreach my $fh_name ( keys %fhs ) { + my $entry = $fhs{$fh_name}; + next if $entry->is_std(); + + my $parent_end = $entry->parent_end(); + my $child_end = $entry->child_end(); + + if ( $entry->direct() ) { + if ( $entry->name_shows_dup() ) { + my $open_prefix + = $entry->parent_is_source() ? '<&' : '>&'; + open $child_end, $open_prefix . $parent_end; + } + else { + $child_end = $parent_end; + $entry->child_end($child_end); + } + } + else { + close $parent_end; + } + + # we want these fh's to stay open after the exec + fcntl $child_end, F_SETFD, 0; + + # now set the options for the call to GnuPG + my $fileno = my_fileno($child_end); + my $option = $fh_name . '_fd'; + $self->options->$option($fileno); + } + + my @command = ( + $self->call(), $self->options->get_args(), + @commands, @command_args + ); + + exec @command or die "exec() error: $ERRNO"; } - + # parent - + # close the child end of any pipes (non-direct stuff) - foreach my $fh_name ( keys %fhs ) - { - my $entry = $fhs{$fh_name}; - close $entry->child_end() unless $entry->direct(); + foreach my $fh_name ( keys %fhs ) { + my $entry = $fhs{$fh_name}; + close $entry->child_end() unless $entry->direct(); } - - - foreach my $fh_name ( keys %fhs ) - { - my $entry = $fhs{$fh_name}; - next unless $entry->parent_is_source(); - - my $parent_end = $entry->parent_end(); - - # close any writing handles if they were a dup - #any real reason for this? It bombs if we're doing - #the automagic >& stuff. - #close $parent_end if $entry->direct(); - - # unbuffer pipes - select( ( select( $parent_end ), $OUTPUT_AUTOFLUSH = 1 )[0] ) - if $parent_end; + + foreach my $fh_name ( keys %fhs ) { + my $entry = $fhs{$fh_name}; + next unless $entry->parent_is_source(); + + my $parent_end = $entry->parent_end(); + + # close any writing handles if they were a dup + #any real reason for this? It bombs if we're doing + #the automagic >& stuff. + #close $parent_end if $entry->direct(); + + # unbuffer pipes + select( ( select($parent_end), $OUTPUT_AUTOFLUSH = 1 )[0] ) + if $parent_end; } - + return $pid; } - -sub my_fileno -{ +sub my_fileno { no strict 'refs'; - my ( $fh ) = @_; + my ($fh) = @_; croak "fh is undefined" unless defined $fh; - return $1 if $fh =~ /^=?(\d+)$/; # is it a fd in itself? + return $1 if $fh =~ /^=?(\d+)$/; # is it a fd in itself? my $fileno = fileno $fh; croak "error determining fileno for $fh: $ERRNO" unless defined $fileno; return $fileno; } -__END__ - ################################################################### - -sub get_public_keys ( $@ ) -{ +sub get_public_keys ( $@ ) { my ( $self, @key_ids ) = @_; - - return $self->get_keys( commands => [ '--list-public-keys' ], - command_args => [ @key_ids ], - ); -} - - -sub get_secret_keys ( $@ ) -{ - my ( $self, @key_ids ) = @_; - - return $self->get_keys( commands => [ '--list-secret-keys' ], - command_args => [ @key_ids ], - ); + return $self->get_keys( + commands => ['--list-public-keys'], + command_args => [@key_ids], + ); } - - -sub get_public_keys_with_sigs ( $@ ) -{ +sub get_secret_keys ( $@ ) { my ( $self, @key_ids ) = @_; - return $self->get_keys( commands => [ '--list-sigs' ], - command_args => [ @key_ids ], - ); + return $self->get_keys( + commands => ['--list-secret-keys'], + command_args => [@key_ids], + ); } +sub get_public_keys_with_sigs ( $@ ) { + my ( $self, @key_ids ) = @_; + return $self->get_keys( + commands => ['--list-sigs'], + command_args => [@key_ids], + ); +} -sub get_keys -{ +sub get_keys { my ( $self, %args ) = @_; - + my $saved_options = $self->options(); my $new_options = $self->options->copy(); - $self->options( $new_options ); - $self->options->push_extra_args( '--with-colons', - '--with-fingerprint', - '--with-fingerprint', - ); - + $self->options($new_options); + $self->options->push_extra_args( + '--with-colons', + '--with-fingerprint', + '--with-fingerprint', + ); + my $stdin = IO::Handle->new(); my $stdout = IO::Handle->new(); - - my $handles = GnuPG::Handles->new( stdin => $stdin, - stdout => $stdout, - ); - - my $pid = $self->wrap_call( handles => $handles, - %args, - ); - + + my $handles = GnuPG::Handles->new( + stdin => $stdin, + stdout => $stdout, + ); + + my $pid = $self->wrap_call( + handles => $handles, + %args, + ); + my @returned_keys; my $current_key; my $current_signed_item; my $current_fingerprinted_key; - + require GnuPG::PublicKey; require GnuPG::SecretKey; - require GnuPG::SubKey; + require GnuPG::SubKey; require GnuPG::Fingerprint; - require GnuPG::UserId; + require GnuPG::UserId; require GnuPG::Signature; - - while ( <$stdout> ) - { - my $line = $_; - chomp $line; - my @fields = split ':', $line; - next unless @fields > 3; - - my $record_type = $fields[0]; - - if ( $record_type eq 'pub' or $record_type eq 'sec' ) - { - push @returned_keys, $current_key - if $current_key; - - my ( $user_id_validity, $key_length, $algo_num, $hex_key_id, - $creation_date_string, $expiration_date_string, - $local_id, $owner_trust, $user_id_string ) - = @fields[1..$#fields]; - - $current_key = $current_fingerprinted_key - = $record_type eq 'pub' - ? GnuPG::PublicKey->new() - : GnuPG::SecretKey->new(); - - $current_key->hash_init - ( length => $key_length, - algo_num => $algo_num, - hex_id => $hex_key_id, - local_id => $local_id, - owner_trust => $owner_trust, - creation_date_string => $creation_date_string, - expiration_date_string => $expiration_date_string, - ); - - $current_signed_item = GnuPG::UserId->new - ( validity => $user_id_validity, - as_string => $user_id_string, - ); - - $current_key->push_user_ids( $current_signed_item ); - } - elsif ( $record_type eq 'fpr' ) - { - my $hex = $fields[9]; - my $f = GnuPG::Fingerprint->new( as_hex_string => $hex ); - $current_fingerprinted_key->fingerprint( $f ); - } - elsif ( $record_type eq 'sig' ) - { - my ( $algo_num, $hex_key_id, - $signature_date_string, $user_id_string ) - = @fields[3..5,9]; - - my $signature = GnuPG::Signature->new - ( algo_num => $algo_num, - hex_id => $hex_key_id, - date_string => $signature_date_string, - user_id_string => $user_id_string, - ); - - if ( $current_signed_item->isa( 'GnuPG::UserId' ) ) - { - $current_signed_item->push_signatures( $signature ); - } - elsif ( $current_signed_item->isa( 'GnuPG::SubKey' ) ) - { - $current_signed_item->signature( $signature ); - } - else - { - warn "do not know how to handle signature line: $line\n"; - } - } - elsif ( $record_type eq 'uid' ) - { - my ( $validity, $user_id_string ) = @fields[1,9]; - - $current_signed_item = GnuPG::UserId->new - ( validity => $validity, - as_string => $user_id_string, - ); - - $current_key->push_user_ids( $current_signed_item ); - } - elsif ( $record_type eq 'sub' or $record_type eq 'ssb' ) - { - my ( $validity, $key_length, $algo_num, $hex_id, - $creation_date_string, $expiration_date_string, - $local_id ) - = @fields[1..7]; - - $current_signed_item = $current_fingerprinted_key - = GnuPG::SubKey->new - ( validity => $validity, - length => $key_length, - algo_num => $algo_num, - hex_id => $hex_id, - creation_date_string => $creation_date_string, - expiration_date_string => $expiration_date_string, - local_id => $local_id, - ); - - $current_key->push_subkeys( $current_signed_item ); - } - elsif ( $record_type ne 'tru' ) - { - warn "unknown record type $record_type"; - } + + while (<$stdout>) { + my $line = $_; + chomp $line; + my @fields = split ':', $line; + next unless @fields > 3; + + my $record_type = $fields[0]; + + if ( $record_type eq 'pub' or $record_type eq 'sec' ) { + push @returned_keys, $current_key + if $current_key; + + my ( + $user_id_validity, $key_length, $algo_num, $hex_key_id, + $creation_date_string, $expiration_date_string, + $local_id, $owner_trust, $user_id_string + ) = @fields[ 1 .. $#fields ]; + + + # GnuPg 2.x uses epoch time for creation and expiration date strings. + # For backward compatibility, we convert them back using GMT; + $creation_date_string = $self->_downrez_gpg2_date($creation_date_string); + $expiration_date_string = $self->_downrez_gpg2_date($expiration_date_string); + + $current_key = $current_fingerprinted_key + = $record_type eq 'pub' + ? GnuPG::PublicKey->new() + : GnuPG::SecretKey->new(); + + $current_key->hash_init( + length => $key_length, + algo_num => $algo_num, + hex_id => $hex_key_id, + local_id => $local_id, + owner_trust => $owner_trust, + creation_date_string => $creation_date_string, + expiration_date_string => $expiration_date_string, + ); + + $current_signed_item = GnuPG::UserId->new( + validity => $user_id_validity, + as_string => $user_id_string, + ); + + $current_key->push_user_ids($current_signed_item); + } + elsif ( $record_type eq 'fpr' ) { + my $hex = $fields[9]; + my $f = GnuPG::Fingerprint->new( as_hex_string => $hex ); + $current_fingerprinted_key->fingerprint($f); + } + elsif ( $record_type eq 'sig' ) { + my ( + $algo_num, $hex_key_id, + $signature_date_string, $user_id_string + ) = @fields[ 3 .. 5, 9 ]; + + $signature_date_string = $self->_downrez_gpg2_date($signature_date_string); + my $signature = GnuPG::Signature->new( + algo_num => $algo_num, + hex_id => $hex_key_id, + date_string => $signature_date_string, + user_id_string => $user_id_string, + ); + + if ( $current_signed_item->isa('GnuPG::UserId') ) { + $current_signed_item->push_signatures($signature); + } + elsif ( $current_signed_item->isa('GnuPG::SubKey') ) { + $current_signed_item->signature($signature); + } + else { + warn "do not know how to handle signature line: $line\n"; + } + } + elsif ( $record_type eq 'uid' ) { + my ( $validity, $user_id_string ) = @fields[ 1, 9 ]; + + $current_signed_item = GnuPG::UserId->new( + validity => $validity, + as_string => $user_id_string, + ); + + $current_key->push_user_ids($current_signed_item); + } + elsif ( $record_type eq 'sub' or $record_type eq 'ssb' ) { + my ( + $validity, $key_length, $algo_num, $hex_id, + $creation_date_string, $expiration_date_string, + $local_id + ) = @fields[ 1 .. 7 ]; + + $creation_date_string = $self->_downrez_gpg2_date($creation_date_string); + $expiration_date_string = $self->_downrez_gpg2_date($expiration_date_string); + $current_signed_item = $current_fingerprinted_key + = GnuPG::SubKey->new( + validity => $validity, + length => $key_length, + algo_num => $algo_num, + hex_id => $hex_id, + creation_date_string => $creation_date_string, + expiration_date_string => $expiration_date_string, + local_id => $local_id, + ); + + $current_key->push_subkeys($current_signed_item); + } + elsif ( $record_type ne 'tru' ) { + warn "unknown record type $record_type"; + } } - + waitpid $pid, 0; - + push @returned_keys, $current_key - if $current_key; - - $self->options( $saved_options ); - + if $current_key; + + $self->options($saved_options); + return @returned_keys; } +sub _downrez_gpg2_date { + my $self = shift; + my $date = shift; + if ($date =~ /^\d+$/) { + my ($year,$month,$day) = (gmtime($date))[5,4,3]; + $year += 1900; + $month += 1; + return sprintf('%04d-%02d-%02d', $year, $month, $day); + } + return $date; +} + ################################################################ - -sub list_public_keys -{ +sub list_public_keys { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--list-public-keys' ], - ); + return $self->wrap_call( + %args, + commands => ['--list-public-keys'], + ); } - -sub list_sigs -{ +sub list_sigs { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--list-sigs' ], - ); + return $self->wrap_call( + %args, + commands => ['--list-sigs'], + ); } - - -sub list_secret_keys -{ +sub list_secret_keys { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--list-secret-keys' ], - ); + return $self->wrap_call( + %args, + commands => ['--list-secret-keys'], + ); } - - -sub encrypt( $% ) -{ +sub encrypt( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--encrypt' ] ); + return $self->wrap_call( + %args, + commands => ['--encrypt'] + ); } - - -sub encrypt_symmetrically( $% ) -{ +sub encrypt_symmetrically( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--symmetric' ] ); + return $self->wrap_call( + %args, + commands => ['--symmetric'] + ); } - - -sub sign( $% ) -{ +sub sign( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--sign' ] ); + return $self->wrap_call( + %args, + commands => ['--sign'] + ); } - - -sub clearsign( $% ) -{ +sub clearsign( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args,, - commands => [ '--clearsign' ] ); + return $self->wrap_call( + %args,, + commands => ['--clearsign'] + ); } - -sub detach_sign( $% ) -{ +sub detach_sign( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--detach-sign' ] ); + return $self->wrap_call( + %args, + commands => ['--detach-sign'] + ); } - - -sub sign_and_encrypt( $% ) -{ +sub sign_and_encrypt( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--sign', - '--encrypt' ] ); + return $self->wrap_call( + %args, + commands => [ + '--sign', + '--encrypt' + ] + ); } - - -sub decrypt( $% ) -{ +sub decrypt( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--decrypt' ] ); + return $self->wrap_call( + %args, + commands => ['--decrypt'] + ); } - - -sub verify( $% ) -{ +sub verify( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--verify' ] ); + return $self->wrap_call( + %args, + commands => ['--verify'] + ); } - - -sub import_keys( $% ) -{ +sub import_keys( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--import' ] ); + return $self->wrap_call( + %args, + commands => ['--import'] + ); } - - -sub export_keys( $% ) -{ +sub export_keys( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--export' ] ); + return $self->wrap_call( + %args, + commands => ['--export'] + ); } - -sub recv_keys( $% ) -{ +sub recv_keys( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--recv-keys' ] ); + return $self->wrap_call( + %args, + commands => ['--recv-keys'] + ); } - - -sub send_keys( $% ) -{ +sub send_keys( $% ) { my ( $self, %args ) = @_; - return $self->wrap_call( %args, - commands => [ '--send-keys' ] ); + return $self->wrap_call( + %args, + commands => ['--send-keys'] + ); } +sub test_default_key_passphrase() { + my ($self) = @_; -sub test_default_key_passphrase() -{ - my ( $self ) = @_; - # We can't do something like let the user pass # in a passphrase handle because we don't exist # anymore after the user runs off with the # attachments croak 'No passphrase defined to test!' - unless defined $self->passphrase(); - - my $stdin = IO::Handle->new(); - my $stdout = IO::Handle->new(); - my $stderr = IO::Handle->new(); - my $status = IO::Handle->new(); - - my $handles = GnuPG::Handles->new - ( stdin => $stdin, - stdout => $stdout, - stderr => $stderr, - status => $status ); - + unless defined $self->passphrase(); + + my $stdin = IO::Handle->new(); + my $stdout = IO::Handle->new(); + my $stderr = IO::Handle->new(); + my $status = IO::Handle->new(); + + my $handles = GnuPG::Handles->new( + stdin => $stdin, + stdout => $stdout, + stderr => $stderr, + status => $status + ); + # save this setting since we need to be in non-interactive mode my $saved_meta_interactive_option = $self->options->meta_interactive(); $self->options->clear_meta_interactive(); - + my $pid = $self->sign( handles => $handles ); - + close $stdin; - + # restore this setting to its original setting - $self->options->meta_interactive( $saved_meta_interactive_option ); - + $self->options->meta_interactive($saved_meta_interactive_option); + # all we realy want to check is the status fh - while ( <$status> ) - { - if ( /^\[GNUPG:\]\s*GOOD_PASSPHRASE/ ) - { - waitpid $pid, 0; - return 1; - } + while (<$status>) { + if (/^\[GNUPG:\]\s*GOOD_PASSPHRASE/) { + waitpid $pid, 0; + return 1; + } } - + # If we didn't catch the regexp above, we'll assume # that the passphrase was incorrect waitpid $pid, 0; return 0; } - 1; ############################################################## - =head1 NAME GnuPG::Interface - Perl interface to GnuPG @@ -801,7 +763,7 @@ decryption, verification, and key-listing parsing. =head2 How Data Member Accessor Methods are Created Each module in the GnuPG::Interface bundle relies -on Class::MethodMaker to generate the get/set methods +on Any::Moose to generate the get/set methods used to set the object's data members. I<This is very important to realize.> This means that any data member which is a list has special @@ -842,13 +804,10 @@ L<perlipc/"Bidirectional Communication with Another Process">. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members. =item hash_init( I<%args> ). -This methods work as described in L<Class::MethodMaker/"new_hash_init">. =back @@ -1016,11 +975,6 @@ keys to list in a key-listing. =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -or L<Class::MethodMaker/"object">. -Please read there for more information. - =over 4 =item call @@ -1277,7 +1231,6 @@ L<GnuPG::Handles>, L<GnuPG::PublicKey>, L<GnuPG::SecretKey>, L<gpg>, -L<Class::MethodMaker>, L<perlipc/"Bidirectional Communication with Another Process"> =head1 AUTHOR @@ -1287,3 +1240,9 @@ GnuPg::Interface is currently maintained by Jesse Vincent <jesse@cpan.org>. Frank J. Tobin, ftobin@cpan.org was the original author of the package. =cut + + +__PACKAGE__->meta->make_immutable; + +1; + diff --git a/lib/GnuPG/Key.pm b/lib/GnuPG/Key.pm index 5d78b56..6cda91e 100644 --- a/lib/GnuPG/Key.pm +++ b/lib/GnuPG/Key.pm @@ -14,23 +14,30 @@ # package GnuPG::Key; - -use strict; - -use Class::MethodMaker - get_set => [ qw( length algo_num hex_id hex_data - creation_date_string expiration_date_string - fingerprint - ) ], - new_hash_init => [ qw( new hash_init ) ]; - - -sub short_hex_id -{ - my ( $self ) = @_; +use Any::Moose; +with qw(GnuPG::HashInit); + +has [ + qw( length + algo_num + hex_id + hex_data + creation_date_string + expiration_date_string + fingerprint + ) + ] => ( + isa => 'Any', + is => 'rw', + ); + +sub short_hex_id { + my ($self) = @_; return substr $self->hex_id(), -8; } +__PACKAGE__->meta->make_immutable; + 1; __END__ @@ -61,13 +68,10 @@ GnuPG::SecretKey, or GnuPG::SubKey objects. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members. =item hash_init( I<%args> ). -This method works as described in L<Class::MethodMaker/"new_hash_init">. =item short_hex_id @@ -78,11 +82,6 @@ of the key. =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -or L<Class::MethodMaker/"object">. -Please read there for more information. - =over 4 =item length @@ -116,6 +115,5 @@ A GnuPG::Fingerprint object. =head1 SEE ALSO L<GnuPG::Fingerprint>, -L<Class::MethodMaker> =cut diff --git a/lib/GnuPG/Options.pm b/lib/GnuPG/Options.pm index 0dd7db9..d82a146 100644 --- a/lib/GnuPG/Options.pm +++ b/lib/GnuPG/Options.pm @@ -14,95 +14,111 @@ # package GnuPG::Options; +use Any::Moose; +with qw(GnuPG::HashInit); + +use constant BOOLEANS => qw( + armor + no_greeting + verbose + no_verbose + quiet + batch + always_trust + rfc1991 + openpgp + force_v3_sigs + no_options + textmode + meta_pgp_5_compatible + meta_pgp_2_compatible + meta_interactive +); + +use constant SCALARS => qw( + homedir + default_key + comment + status_fd + logger_fd + passphrase_fd + command_fd + compress_algo + options + meta_signing_key + meta_signing_key_id +); + +use constant LISTS => qw( + encrypt_to + recipients + meta_recipients_keys + meta_recipients_key_ids + extra_args +); + +has $_ => ( + isa => 'Bool', + is => 'rw', + clearer => 'clear_' . $_, +) for BOOLEANS; + +has $_ => ( + isa => 'Any', + is => 'rw', + clearer => 'clear_' . $_, +) for SCALARS; + +for my $list (LISTS) { + has $list => ( + isa => 'ArrayRef', + is => 'rw', + lazy => 1, + clearer => "clear_$list", + default => sub { [] }, + auto_deref => 1, + ); + __PACKAGE__->meta->add_method("push_$list" => sub { + my $self = shift; + push @{ $self->$list }, @_; + }); +} -use strict; - -use constant BOOLEANS => qw( armor - no_greeting - verbose no_verbose quiet - batch - always_trust - rfc1991 openpgp - force_v3_sigs - no_options - textmode - - meta_pgp_5_compatible - meta_pgp_2_compatible - meta_interactive - ); - -use constant SCALARS => qw( homedir - default_key - comment - status_fd logger_fd passphrase_fd - command_fd - compress_algo - options - - meta_signing_key - meta_signing_key_id - ); - -use constant LISTS => qw( encrypt_to - recipients - meta_recipients_keys - meta_recipients_key_ids - extra_args - ); - -use Class::MethodMaker - boolean => [ BOOLEANS ], - get_set => [ SCALARS ], - list => [ LISTS ], - new_with_init => 'new', - new_hash_init => 'hash_init'; - - -sub init -{ - my ( $self, %args ) = @_; - +sub BUILD { + my ( $self, $args ) = @_; $self->hash_init( meta_interactive => 1 ); - $self->hash_init( %args ); + $self->hash_init(%$args); } +sub copy { + my ($self) = @_; + my $new = ( ref $self )->new(); -sub copy -{ - my ( $self ) = @_; - - my $new = (ref $self)->new(); - - foreach my $field ( BOOLEANS, SCALARS, LISTS ) - { - $new->$field( $self->$field() ); + foreach my $field ( BOOLEANS, SCALARS, LISTS ) { + my $value = $self->$field(); + next unless $value; + $new->$field($value); } - + return $new; } +sub get_args { + my ($self) = @_; - -sub get_args -{ - my ( $self ) = @_; - - return ( $self->get_meta_args(), - $self->get_option_args(), - $self->extra_args(), - ); + return ( + $self->get_meta_args(), + $self->get_option_args(), + $self->extra_args(), + ); } - - -sub get_option_args -{ - my ( $self ) = @_; +sub get_option_args { + my ($self) = @_; my @args = (); - + push @args, '--homedir', $self->homedir() if $self->homedir(); push @args, '--options', $self->options() if $self->options(); push @args, '--no-options' if $self->no_options(); @@ -115,59 +131,58 @@ sub get_option_args push @args, '--quiet' if $self->quiet(); push @args, '--batch' if $self->batch(); push @args, '--always-trust' if $self->always_trust(); - push @args, '--comment', $self->comment() if defined $self->comment(); - push @args, '--force-v3-sigs' if $self->force_v3_sigs(); - push @args, '--rfc1991' if $self->rfc1991; - push @args, '--openpgp' if $self->openpgp(); + push @args, '--comment', $self->comment() if defined $self->comment(); + push @args, '--force-v3-sigs' if $self->force_v3_sigs(); + push @args, '--rfc1991' if $self->rfc1991; + push @args, '--openpgp' if $self->openpgp(); push @args, '--compress-algo', $self->compress_algo() - if defined $self->compress_algo(); - - push @args, '--status-fd', $self->status_fd() - if defined $self->status_fd(); - push @args, '--logger-fd', $self->logger_fd() - if defined $self->logger_fd(); - push @args, '--passphrase-fd', $self->passphrase_fd() - if defined $self->passphrase_fd(); - push @args, '--command-fd', $self->command_fd() - if defined $self->command_fd(); - - push @args, map { ( '--recipient', $_ ) } $self->recipients(); + if defined $self->compress_algo(); + + push @args, '--status-fd', $self->status_fd() + if defined $self->status_fd(); + push @args, '--logger-fd', $self->logger_fd() + if defined $self->logger_fd(); + push @args, '--passphrase-fd', $self->passphrase_fd() + if defined $self->passphrase_fd(); + push @args, '--command-fd', $self->command_fd() + if defined $self->command_fd(); + + push @args, map { ( '--recipient', $_ ) } $self->recipients(); push @args, map { ( '--encrypt-to', $_ ) } $self->encrypt_to(); - + return @args; } +sub get_meta_args { + my ($self) = @_; - -sub get_meta_args -{ - my ( $self ) = @_; - my @args = (); - - push @args, '--compress-algo', 1, '--force-v3-sigs' - if $self->meta_pgp_5_compatible(); - push @args, '--rfc1991' if $self->meta_pgp_2_compatible(); - push @args, '--batch', '--no-tty' if not $self->meta_interactive(); - + + push @args, '--compress-algo', 1, '--force-v3-sigs' + if $self->meta_pgp_5_compatible(); + push @args, '--rfc1991' if $self->meta_pgp_2_compatible(); + push @args, '--batch', '--no-tty' if not $self->meta_interactive(); + # To eliminate confusion, we'll move to having any options # that deal with keys end in _id(s) if they only take # an id; otherwise we assume that a GnuPG::Key push @args, '--default-key', $self->meta_signing_key_id() - if $self->meta_signing_key_id(); + if $self->meta_signing_key_id(); push @args, '--default-key', $self->meta_signing_key()->hex_id() - if $self->meta_signing_key(); - - push @args, map { ( '--recipient', $_ ) } $self->meta_recipients_key_ids(); - push @args, map { ( '--recipient', $_->hex_id() ) } $self->meta_recipients_keys(); - + if $self->meta_signing_key(); + + push @args, + map { ( '--recipient', $_ ) } $self->meta_recipients_key_ids(); + push @args, + map { ( '--recipient', $_->hex_id() ) } $self->meta_recipients_keys(); + return @args; } +__PACKAGE__->meta->make_immutable; 1; - __END__ =head1 NAME @@ -192,13 +207,10 @@ own, but rather as part of a GnuPG::Interface object. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members. =item hash_init( I<%args> ). -This method works as described in L<Class::MethodMaker/"new_hash_init">. =item copy @@ -214,11 +226,6 @@ and then I<extra_args>, in that order. =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"boolean">, -L<Class::MethodMaker/"get_set">, L<Class::MethodMaker/"object">, -and L<Class::MethodMaker/"list">. Please read there for more information. - =over 4 =item homedir @@ -343,6 +350,5 @@ Useful to pass an argument not yet covered in this package. =head1 SEE ALSO L<GnuPG::Interface>, -L<Class::MethodMaker> =cut diff --git a/lib/GnuPG/PrimaryKey.pm b/lib/GnuPG/PrimaryKey.pm index 82a8bcc..d84bfa7 100644 --- a/lib/GnuPG/PrimaryKey.pm +++ b/lib/GnuPG/PrimaryKey.pm @@ -14,14 +14,31 @@ # package GnuPG::PrimaryKey; +use Any::Moose; -use strict; +BEGIN { extends qw( GnuPG::Key ) } -use base qw( GnuPG::Key ); +for my $list (qw(user_ids subkeys)) { + has $list => ( + isa => 'ArrayRef', + is => 'rw', + default => sub { [] }, + auto_deref => 1, + ); -use Class::MethodMaker - list => [ qw( user_ids subkeys ) ], - get_set => [ qw( local_id owner_trust ) ]; + __PACKAGE__->meta->add_method("push_$list" => sub { + my $self = shift; + push @{ $self->$list }, @_; + }); +} + +has $_ => ( + isa => 'Any', + is => 'rw', + clearer => 'clear_' . $_, +) for qw( local_id owner_trust ); + +__PACKAGE__->meta->make_immutable; 1; @@ -55,11 +72,6 @@ in L<GnuPG::Key>. =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -L<Class::MethodMaker/"object">, or L<Class::MethodMaker/"list">. -Please read there for more information. - =over 4 =item user_ids @@ -86,6 +98,5 @@ See GnuPG's DETAILS file for details. L<GnuPG::Key>, L<GnuPG::UserId>, L<GnuPG::SubKey>, -L<Class::MethodMaker> =cut diff --git a/lib/GnuPG/PublicKey.pm b/lib/GnuPG/PublicKey.pm index ce4901e..723266f 100644 --- a/lib/GnuPG/PublicKey.pm +++ b/lib/GnuPG/PublicKey.pm @@ -14,10 +14,11 @@ # package GnuPG::PublicKey; +use Any::Moose; -use strict; +BEGIN { extends qw( GnuPG::PrimaryKey ) } -use base qw( GnuPG::PrimaryKey ); +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/GnuPG/SecretKey.pm b/lib/GnuPG/SecretKey.pm index 8d8f9f5..18cc161 100644 --- a/lib/GnuPG/SecretKey.pm +++ b/lib/GnuPG/SecretKey.pm @@ -14,10 +14,11 @@ # package GnuPG::SecretKey; +use Any::Moose; -use strict; +BEGIN { extends qw( GnuPG::PrimaryKey ) } -use base qw( GnuPG::PrimaryKey ); +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/GnuPG/Signature.pm b/lib/GnuPG/Signature.pm index ed5d676..f492aec 100644 --- a/lib/GnuPG/Signature.pm +++ b/lib/GnuPG/Signature.pm @@ -14,14 +14,14 @@ # package GnuPG::Signature; +use Any::Moose; -use strict; +has [qw( algo_num hex_id user_id_string date_string )] => ( + isa => 'Any', + is => 'rw', +); -use Class::MethodMaker - get_set => [ qw( algo_num hex_id user_id_string - date_string - ) ], - new_hash_init => 'new'; +__PACKAGE__->meta->make_immutable; 1; @@ -49,19 +49,12 @@ They embody various aspects of a GnuPG signature on a key. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members. =back =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -L<Class::MethodMaker/"object">, or L<Class::MethodMaker/"list">. -Please read there for more information. - =over 4 =item algo_num @@ -85,6 +78,5 @@ The formatted date the signature was performed on. =head1 SEE ALSO -See also L<Class::MethodMaker>. =cut diff --git a/lib/GnuPG/SubKey.pm b/lib/GnuPG/SubKey.pm index f700ff0..4866b1d 100644 --- a/lib/GnuPG/SubKey.pm +++ b/lib/GnuPG/SubKey.pm @@ -14,13 +14,15 @@ # package GnuPG::SubKey; +use Any::Moose; +BEGIN { extends qw( GnuPG::Key ) } -use strict; +has [qw( validity owner_trust local_id signature )] => ( + isa => 'Any', + is => 'rw', +); -use base qw( GnuPG::Key ); - -use Class::MethodMaker - get_set => [ qw( validity owner_trust local_id signature ) ]; +__PACKAGE__->meta->make_immutable; 1; @@ -49,11 +51,6 @@ in L<GnuPG::Key>. =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -L<Class::MethodMaker/"object">, or L<Class::MethodMaker/"list">. -Please read there for more information. - =over 4 =item validity @@ -82,6 +79,5 @@ signature on this key. L<GnuPG::Key>, L<GnuPG::Signature>, -L<Class::MethodMaker> =cut diff --git a/lib/GnuPG/UserId.pm b/lib/GnuPG/UserId.pm index b75b13c..ad37ea5 100644 --- a/lib/GnuPG/UserId.pm +++ b/lib/GnuPG/UserId.pm @@ -14,22 +14,33 @@ # package GnuPG::UserId; - -use strict; - -use Class::MethodMaker - get_set => [ qw( validity as_string ) ], - list => [ qw( signatures ) ], - new_hash_init => 'new'; +use Any::Moose; + +has [qw( validity as_string )] => ( + isa => 'Any', + is => 'rw', +); + +has signatures => ( + isa => 'ArrayRef', + is => 'rw', + default => sub { [] }, +); + +sub push_signatures { + my $self = shift; + push @{ $self->signatures }, @_; +} # DEPRECATED -sub user_id_string -{ +sub user_id_string { my ( $self, $v ) = @_; - $self->as_string( $v ) if defined $v; + $self->as_string($v) if defined $v; return $self->as_string(); } +__PACKAGE__->meta->make_immutable; + 1; __END__ @@ -56,19 +67,12 @@ objects. =item new( I<%initialization_args> ) This methods creates a new object. The optional arguments are -initialization of data members; the initialization is done -in a manner according to the method created as described -in L<Class::MethodMaker/"new_hash_init">. +initialization of data members; =back =head1 OBJECT DATA MEMBERS -Note that these data members are interacted with via object methods -created using the methods described in L<Class::MethodMaker/"get_set">, -L<Class::MethodMaker/"object">, or L<Class::MethodMaker/"list">. -Please read there for more information. - =over 4 =item as_string @@ -91,6 +95,5 @@ on this user id. =head1 SEE ALSO L<GnuPG::Signature>, -L<Class::MethodMaker> =cut diff --git a/t/GnuPG/ComparableFingerprint.pm b/t/GnuPG/ComparableFingerprint.pm index 940a6ae..6a0632a 100644 --- a/t/GnuPG/ComparableFingerprint.pm +++ b/t/GnuPG/ComparableFingerprint.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparableFingerprint.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparableFingerprint.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparableFingerprint; diff --git a/t/GnuPG/ComparableKey.pm b/t/GnuPG/ComparableKey.pm index 2808fcd..0e3b5e1 100644 --- a/t/GnuPG/ComparableKey.pm +++ b/t/GnuPG/ComparableKey.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparableKey.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparableKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparableKey; diff --git a/t/GnuPG/ComparablePrimaryKey.pm b/t/GnuPG/ComparablePrimaryKey.pm index 64df495..24f7d1f 100644 --- a/t/GnuPG/ComparablePrimaryKey.pm +++ b/t/GnuPG/ComparablePrimaryKey.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparablePrimaryKey.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparablePrimaryKey.pm,v 1.3 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparablePrimaryKey; diff --git a/t/GnuPG/ComparablePublicKey.pm b/t/GnuPG/ComparablePublicKey.pm index 44fc91d..2137850 100644 --- a/t/GnuPG/ComparablePublicKey.pm +++ b/t/GnuPG/ComparablePublicKey.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparablePublicKey.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparablePublicKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparablePublicKey; diff --git a/t/GnuPG/ComparableSecretKey.pm b/t/GnuPG/ComparableSecretKey.pm index 5362351..3f3858f 100644 --- a/t/GnuPG/ComparableSecretKey.pm +++ b/t/GnuPG/ComparableSecretKey.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparableSecretKey.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparableSecretKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparableSecretKey; diff --git a/t/GnuPG/ComparableSignature.pm b/t/GnuPG/ComparableSignature.pm index c205f9e..d8e82f4 100644 --- a/t/GnuPG/ComparableSignature.pm +++ b/t/GnuPG/ComparableSignature.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparableSignature.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparableSignature.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparableSignature; diff --git a/t/GnuPG/ComparableSubKey.pm b/t/GnuPG/ComparableSubKey.pm index 948654a..c6a6ef2 100644 --- a/t/GnuPG/ComparableSubKey.pm +++ b/t/GnuPG/ComparableSubKey.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparableSubKey.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparableSubKey.pm,v 1.4 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparableSubKey; diff --git a/t/GnuPG/ComparableUserId.pm b/t/GnuPG/ComparableUserId.pm index 8a37782..11efc40 100644 --- a/t/GnuPG/ComparableUserId.pm +++ b/t/GnuPG/ComparableUserId.pm @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: ComparableUserId.pm 22107 2008-06-24 05:48:08Z dmn $ +# $Id: ComparableUserId.pm,v 1.3 2001/09/14 12:34:36 ftobin Exp $ # package GnuPG::ComparableUserId; diff --git a/t/MyTestSpecific.pm b/t/MyTestSpecific.pm index 09a2371..629c673 100644 --- a/t/MyTestSpecific.pm +++ b/t/MyTestSpecific.pm @@ -39,7 +39,14 @@ use vars qw( @ISA @EXPORT ); -$gpg_program = 'gpg'; +for my $gpg qw(gpg gpg2) { + my $gpg_find = "which $gpg"; + print "$gpg_find ... "; + system($gpg_find); + if ( $? != 0 ) { + die "gpg (GnuPG) not found"; + } else { $gpg_program = $gpg; last } +} $gnupg = GnuPG::Interface->new( gnupg_call => $gpg_program, passphrase => 'test', diff --git a/test/public-keys-sigs/1.out b/test/public-keys-sigs/1.out new file mode 100755 index 0000000..f1e9d53 --- /dev/null +++ b/test/public-keys-sigs/1.out @@ -0,0 +1,30 @@ +test/pubring.gpg +---------------- +pub 1024D/F950DA9C 2000-02-06 +uid GnuPG test key (for testing purposes only) +sig 3 F950DA9C 2007-04-20 GnuPG test key (for testing purposes only) +sig 260C4FA3 2000-03-16 Frank J. Tobin <ftobin@neverending.org> +sig 3 F950DA9C 2000-02-06 GnuPG test key (for testing purposes only) +uid Foo Bar (1) +sig 3 F950DA9C 2007-04-20 GnuPG test key (for testing purposes only) +sig 260C4FA3 2000-03-16 Frank J. Tobin <ftobin@neverending.org> +sig 3 F950DA9C 2000-03-16 GnuPG test key (for testing purposes only) +sub 768g/2E854A6B 2000-02-06 +sig F950DA9C 2007-04-20 GnuPG test key (for testing purposes only) + +pub 1024D/260C4FA3 1999-04-22 [expired: 2001-04-21] +uid Frank J. Tobin <ftobin@neverending.org> +sig 3 260C4FA3 1999-07-02 Frank J. Tobin <ftobin@neverending.org> +sig 164BDBAE 1999-11-16 [User ID not found] +uid Frank J. Tobin <ftobin@bigfoot.com> +sig 3 260C4FA3 1999-04-22 Frank J. Tobin <ftobin@neverending.org> +sig F40EB65E 1999-04-22 [User ID not found] +sig 164BDBAE 1999-11-16 [User ID not found] +uid Dekan +sig 3 260C4FA3 1999-04-22 Frank J. Tobin <ftobin@neverending.org> +sig F40EB65E 1999-04-22 [User ID not found] +sig 164BDBAE 1999-11-16 [User ID not found] +uid Frank J. Tobin <ftobin@uiuc.edu> +sig 3 260C4FA3 1999-06-29 Frank J. Tobin <ftobin@neverending.org> +sig 164BDBAE 1999-11-16 [User ID not found] + diff --git a/test/public-keys-sigs/2.out b/test/public-keys-sigs/2.out new file mode 100755 index 0000000..cdf8cce --- /dev/null +++ b/test/public-keys-sigs/2.out @@ -0,0 +1,12 @@ +pub 1024D/F950DA9C 2000-02-06 +uid GnuPG test key (for testing purposes only) +sig 3 F950DA9C 2007-04-20 GnuPG test key (for testing purposes only) +sig 260C4FA3 2000-03-16 Frank J. Tobin <ftobin@neverending.org> +sig 3 F950DA9C 2000-02-06 GnuPG test key (for testing purposes only) +uid Foo Bar (1) +sig 3 F950DA9C 2007-04-20 GnuPG test key (for testing purposes only) +sig 260C4FA3 2000-03-16 Frank J. Tobin <ftobin@neverending.org> +sig 3 F950DA9C 2000-03-16 GnuPG test key (for testing purposes only) +sub 768g/2E854A6B 2000-02-06 +sig F950DA9C 2007-04-20 GnuPG test key (for testing purposes only) + diff --git a/test/public-keys/1.out b/test/public-keys/1.out new file mode 100755 index 0000000..2102afa --- /dev/null +++ b/test/public-keys/1.out @@ -0,0 +1,13 @@ +test/pubring.gpg +---------------- +pub 1024D/F950DA9C 2000-02-06 +uid GnuPG test key (for testing purposes only) +uid Foo Bar (1) +sub 768g/2E854A6B 2000-02-06 + +pub 1024D/260C4FA3 1999-04-22 [expired: 2001-04-21] +uid Frank J. Tobin <ftobin@neverending.org> +uid Frank J. Tobin <ftobin@bigfoot.com> +uid Dekan +uid Frank J. Tobin <ftobin@uiuc.edu> + diff --git a/test/public-keys/2.out b/test/public-keys/2.out new file mode 100755 index 0000000..2102afa --- /dev/null +++ b/test/public-keys/2.out @@ -0,0 +1,13 @@ +test/pubring.gpg +---------------- +pub 1024D/F950DA9C 2000-02-06 +uid GnuPG test key (for testing purposes only) +uid Foo Bar (1) +sub 768g/2E854A6B 2000-02-06 + +pub 1024D/260C4FA3 1999-04-22 [expired: 2001-04-21] +uid Frank J. Tobin <ftobin@neverending.org> +uid Frank J. Tobin <ftobin@bigfoot.com> +uid Dekan +uid Frank J. Tobin <ftobin@uiuc.edu> + diff --git a/test/random_seed b/test/random_seed Binary files differnew file mode 100755 index 0000000..f7a2233 --- /dev/null +++ b/test/random_seed diff --git a/test/secret-keys/1.out b/test/secret-keys/1.out new file mode 100755 index 0000000..5999484 --- /dev/null +++ b/test/secret-keys/1.out @@ -0,0 +1,7 @@ +test/secring.gpg +---------------- +sec 1024D/F950DA9C 2000-02-06 +uid GnuPG test key (for testing purposes only) +uid Foo Bar (1) +ssb 768g/2E854A6B 2000-02-06 + diff --git a/test/secret-keys/2.out b/test/secret-keys/2.out new file mode 100755 index 0000000..3d2f61d --- /dev/null +++ b/test/secret-keys/2.out @@ -0,0 +1,5 @@ +sec 1024D/F950DA9C 2000-02-06 +uid GnuPG test key (for testing purposes only) +uid Foo Bar (1) +ssb 768g/2E854A6B 2000-02-06 + diff --git a/test/temp b/test/temp new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/test/temp diff --git a/test/trustdb.gpg b/test/trustdb.gpg Binary files differnew file mode 100755 index 0000000..92da441 --- /dev/null +++ b/test/trustdb.gpg |