| Data-GUID-URLSafe documentation | Contained in the Data-GUID-URLSafe distribution. |
Data::GUID::URLSafe - url-safe base64-encoded GUIDs
version 0.004
use Data::GUID::URLSafe; my $guid = Data::GUID->new; my $string = $guid->as_base64_urlsafe; my $same_guid = Data::GUID->from_base64_urlsafe;
This module provides methods for Data::GUID that provide for URL-safe base64 encoded GUIDs, as described by MIME::Base64::URLSafe.
These strings are also safer for email addresses. While the forward slash is legal in email addresses, some broken email address validators reject it. (Also, without the trailing equals signs, these strings will be shorter.)
When Data::GUID::URLSafe is use'd, it installs methods into Data::GUID using
Sub::Exporter.
my $string = $guid->as_base64_urlsafe;
This method returns the URL-safe base64 encoded representation of the GUID.
my $guid = Data::GUID->from_base64_urlsafe($string);
Ricardo SIGNES, <rjbs at cpan.org>
Please report any bugs or feature requests through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-GUID-URLSafe. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
Copyright 2007 Ricardo SIGNES.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Data-GUID-URLSafe documentation | Contained in the Data-GUID-URLSafe distribution. |
use strict; package Data::GUID::URLSafe;
$Data::GUID::URLSafe::VERSION = '0.004';
use Data::GUID (); use Sub::Exporter -setup => { into => 'Data::GUID', exports => [ qw(as_base64_urlsafe from_base64_urlsafe) ], groups => [ default => [ -all ] ], };
sub as_base64_urlsafe { my ($self) = @_; my $base64 = $self->as_base64; $base64 =~ tr{+/=}{-_}d; return $base64; }
sub from_base64_urlsafe { my ($self, $string) = @_; # +/ should not be handled, so convert them to invalid chars # also, remove spaces (\t..\r and SP) so as to calc padding len $string =~ tr{-_\t-\x0d }{+/}d; if (my $mod4 = length($string) % 4) { $string .= substr('====', $mod4); } return $self->from_base64($string); }
1;