Created
November 23, 2013 20:32
-
-
Save retupmoca/7619564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
#`[ | |
This is an ugly hack to make sure the dependencies are precompiled first | |
use MIME::Base64::PIR; | |
use MIME::Base64::Perl; | |
(some of our tools do a text-based search for 'use' lines, | |
and don't know about multi-line comments) | |
] | |
class MIME::Base64:auth<cpan:SNARKY>:ver<1.1> { | |
my $default-backend; | |
has $.backend; | |
use MIME::Base64::Perl; | |
BEGIN eval 'use MIME::Base64::PIR' if $*VM<name> eq 'parrot'; | |
if $*VM<name> eq 'parrot' { | |
$default-backend = ::('MIME::Base64::PIR'); | |
} else { | |
$default-backend = MIME::Base64::Perl; | |
} | |
method new($backend = 0) { | |
if $backend ~~ Numeric { | |
return self.bless(backend => $default-backend); | |
} else { | |
return self.bless(backend => $backend); | |
} | |
} | |
method set-backend($class){ | |
if self { | |
self.backend = $class; | |
} else { | |
$default-backend = $class; | |
} | |
} | |
method get-backend() { | |
if self { | |
return self.backend; | |
} else { | |
return $default-backend; | |
} | |
} | |
method encode(Blob $data, :$oneline --> Str) { | |
if self { | |
return self.backend.encode($data, :$oneline); | |
} else { | |
return $default-backend.encode($data, :$oneline); | |
} | |
} | |
method decode(Str $encoded --> Buf) { | |
if self { | |
return self.backend.decode($encoded); | |
} else { | |
return $default-backend.decode($encoded); | |
} | |
} | |
method encode-str(Str $string, :$oneline --> Str) { | |
return self.encode($string.encode('utf8'), :$oneline); | |
} | |
method decode-str(Str $encoded --> Str) { | |
return self.decode($encoded).decode('utf8'); | |
} | |
# compatibility methods | |
method encode_base64(Str $str --> Str) { | |
return self.encode-str($str); | |
} | |
method decode_base64(Str $str --> Str) { | |
return self.decode-str($str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error after precompilation:
$ prove -e perl6-p t/
t/basic.t .. ===SORRY!===
Missing or wrong version of dependency 'PIR.pm6'
t/basic.t .. Dubious, test returned 1 (wstat 256, 0x100)
No subtests run
Test Summary Report
t/basic.t (Wstat: 256 Tests: 0 Failed: 0)
Non-zero exit status: 1
Parse errors: No plan found in TAP output
Files=1, Tests=0, 2 wallclock secs ( 0.03 usr 0.00 sys + 1.61 cusr 0.39 csys = 2.03 CPU)
Result: FAIL