AutoSession

 view release on metacpan or  search on metacpan

lib/AutoSession/Base64.pm  view on Meta::CPAN

  if ( $BASE64_PM ) { return &MIME::Base64::encode_base64($_[0]) ;}
  else { return &_encode_base64_pure_perl($_[0]) ;}
}

############################
# _ENCODE_BASE64_PURE_PERL #
############################

sub _encode_base64_pure_perl {
  my $res = "";
  my $eol = $_[1];
  $eol = "\n" unless defined $eol;
  pos($_[0]) = 0;                          # ensure start at the beginning
  while ($_[0] =~ /(.{1,45})/gs) {
	$res .= substr(pack('u', $1), 1);
	chop($res);
  }
  $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
  # fix padding at the end
  my $padding = (3 - length($_[0]) % 3) % 3;
  $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
  # break encoded string into lines of no more than 76 characters each
  if (length $eol) {
	$res =~ s/(.{1,76})/$1$eol/g;
  }
  $res;
}

#################
# DECODE_BASE64 #
#################

sub decode_base64 {
  if ( $BASE64_PM ) { return &MIME::Base64::decode_base64($_[0]) ;}



( run in 2.673 seconds using v1.01-cache-2.11-cpan-98e64b0badf )