r56887 - in /branches/upstream/libscalar-string-perl: ./ current/ current/lib/ current/lib/Scalar/ current/t/
ivan at users.alioth.debian.org
ivan at users.alioth.debian.org
Mon Apr 26 00:26:13 UTC 2010
Author: ivan
Date: Mon Apr 26 00:26:02 2010
New Revision: 56887
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=56887
Log:
[svn-inject] Installing original source of libscalar-string-perl
Added:
branches/upstream/libscalar-string-perl/
branches/upstream/libscalar-string-perl/current/
branches/upstream/libscalar-string-perl/current/.cvsignore
branches/upstream/libscalar-string-perl/current/Build.PL
branches/upstream/libscalar-string-perl/current/Changes
branches/upstream/libscalar-string-perl/current/MANIFEST
branches/upstream/libscalar-string-perl/current/META.yml
branches/upstream/libscalar-string-perl/current/Makefile.PL
branches/upstream/libscalar-string-perl/current/README
branches/upstream/libscalar-string-perl/current/SIGNATURE
branches/upstream/libscalar-string-perl/current/lib/
branches/upstream/libscalar-string-perl/current/lib/Scalar/
branches/upstream/libscalar-string-perl/current/lib/Scalar/.cvsignore
branches/upstream/libscalar-string-perl/current/lib/Scalar/String.pm
branches/upstream/libscalar-string-perl/current/lib/Scalar/String.xs
branches/upstream/libscalar-string-perl/current/t/
branches/upstream/libscalar-string-perl/current/t/grade.t
branches/upstream/libscalar-string-perl/current/t/grade_pp.t
branches/upstream/libscalar-string-perl/current/t/pod_cvg.t
branches/upstream/libscalar-string-perl/current/t/pod_syn.t
branches/upstream/libscalar-string-perl/current/t/setup_pp.pl
Added: branches/upstream/libscalar-string-perl/current/.cvsignore
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/.cvsignore?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/.cvsignore (added)
+++ branches/upstream/libscalar-string-perl/current/.cvsignore Mon Apr 26 00:26:02 2010
@@ -1,0 +1,4 @@
+Build Makefile
+_build blib
+META.yml Makefile.PL SIGNATURE
+Scalar-String-*
Added: branches/upstream/libscalar-string-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/Build.PL?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/Build.PL (added)
+++ branches/upstream/libscalar-string-perl/current/Build.PL Mon Apr 26 00:26:02 2010
@@ -1,0 +1,68 @@
+use warnings;
+use strict;
+
+use Module::Build;
+
+Module::Build->subclass(code => q{
+ unless(__PACKAGE__->can("cbuilder")) {
+ *cbuilder = sub { $_[0]->_cbuilder or die "no C support" };
+ }
+ unless(__PACKAGE__->can("have_c_compiler")) {
+ *have_c_compiler = sub {
+ my $cb = eval { $_[0]->cbuilder };
+ return $cb && $cb->have_compiler;
+ };
+ }
+ if($Module::Build::VERSION < 0.33) {
+ # Older versions of Module::Build have a bug where if the
+ # cbuilder object is used at Build.PL time (which it will
+ # be for this distribution due to the logic in
+ # ->find_xs_files) then that object can be dumped to the
+ # build_params file, and then at Build time it will
+ # attempt to use the dumped blessed object without loading
+ # the ExtUtils::CBuilder class that is needed to make it
+ # work.
+ *write_config = sub {
+ delete $_[0]->{properties}->{_cbuilder};
+ return $_[0]->SUPER::write_config;
+ };
+ }
+ sub find_xs_files {
+ my($self) = @_;
+ return {} unless $self->have_c_compiler;
+ return $self->SUPER::find_xs_files;
+ }
+})->new(
+ module_name => "Scalar::String",
+ dist_version => "0.000",
+ license => "perl",
+ build_requires => {
+ "Module::Build" => 0,
+ "Test::More" => 0,
+ "perl" => "5.006",
+ "strict" => 0,
+ "warnings" => 0,
+ },
+ build_recommends => {
+ "ExtUtils::CBuilder" => "0.15",
+ },
+ requires => {
+ "Carp" => 0,
+ "Exporter" => 0,
+ "bytes" => 0,
+ "if" => 0,
+ "perl" => "5.006",
+ "strict" => 0,
+ "utf8" => 0,
+ "warnings" => 0,
+ },
+ recommends => {
+ "XSLoader" => 0,
+ },
+ dynamic_config => 1,
+ meta_add => { distribution_type => "module" },
+ create_makefile_pl => "passthrough",
+ sign => 1,
+)->create_build_script;
+
+exit 0;
Added: branches/upstream/libscalar-string-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/Changes?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/Changes (added)
+++ branches/upstream/libscalar-string-perl/current/Changes Mon Apr 26 00:26:02 2010
@@ -1,0 +1,3 @@
+version 0.000; 2009-03-14
+
+ * initial released version
Added: branches/upstream/libscalar-string-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/MANIFEST?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/MANIFEST (added)
+++ branches/upstream/libscalar-string-perl/current/MANIFEST Mon Apr 26 00:26:02 2010
@@ -1,0 +1,16 @@
+.cvsignore
+Build.PL
+Changes
+MANIFEST
+META.yml
+Makefile.PL
+README
+lib/Scalar/.cvsignore
+lib/Scalar/String.pm
+lib/Scalar/String.xs
+t/grade.t
+t/grade_pp.t
+t/pod_cvg.t
+t/pod_syn.t
+t/setup_pp.pl
+SIGNATURE Added here by Module::Build
Added: branches/upstream/libscalar-string-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/META.yml?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/META.yml (added)
+++ branches/upstream/libscalar-string-perl/current/META.yml Mon Apr 26 00:26:02 2010
@@ -1,0 +1,36 @@
+---
+name: Scalar-String
+version: 0.000
+author:
+ - 'Andrew Main (Zefram) <zefram at fysh.org>'
+abstract: string aspects of scalars
+license: perl
+resources:
+ license: ~
+requires:
+ Carp: 0
+ Exporter: 0
+ bytes: 0
+ if: 0
+ perl: 5.006
+ strict: 0
+ utf8: 0
+ warnings: 0
+build_requires:
+ Module::Build: 0
+ Test::More: 0
+ perl: 5.006
+ strict: 0
+ warnings: 0
+recommends:
+ XSLoader: 0
+dynamic_config: 1
+provides:
+ Scalar::String:
+ file: lib/Scalar/String.pm
+ version: 0.000
+generated_by: Module::Build version 0.31012
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.2.html
+ version: 1.2
+distribution_type: module
Added: branches/upstream/libscalar-string-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/Makefile.PL?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/Makefile.PL (added)
+++ branches/upstream/libscalar-string-perl/current/Makefile.PL Mon Apr 26 00:26:02 2010
@@ -1,0 +1,32 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.31012
+require 5.006;
+
+ unless (eval "use Module::Build::Compat 0.02; 1" ) {
+ print "This module requires Module::Build to install itself.\n";
+
+ require ExtUtils::MakeMaker;
+ my $yn = ExtUtils::MakeMaker::prompt
+ (' Install Module::Build now from CPAN?', 'y');
+
+ unless ($yn =~ /^y/i) {
+ die " *** Cannot install without Module::Build. Exiting ...\n";
+ }
+
+ require Cwd;
+ require File::Spec;
+ require CPAN;
+
+ # Save this 'cause CPAN will chdir all over the place.
+ my $cwd = Cwd::cwd();
+
+ CPAN::Shell->install('Module::Build::Compat');
+ CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
+ or die "Couldn't install Module::Build, giving up.\n";
+
+ chdir $cwd or die "Cannot chdir() back to $cwd: $!";
+ }
+ eval "use Module::Build::Compat 0.02; 1" or die $@;
+ use lib '_build/lib';
+ Module::Build::Compat->run_build_pl(args => \@ARGV);
+ require MyModuleBuilder;
+ Module::Build::Compat->write_makefile(build_class => 'MyModuleBuilder');
Added: branches/upstream/libscalar-string-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/README?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/README (added)
+++ branches/upstream/libscalar-string-perl/current/README Mon Apr 26 00:26:02 2010
@@ -1,0 +1,38 @@
+NAME
+
+Scalar::String - string aspects of scalars
+
+DESCRIPTION
+
+This module is about the string part of plain Perl scalars. A scalar has
+a string value, which is notionally a sequence of Unicode codepoints, but
+may be internally encoded in either ISO-8859-1 or UTF-8. In places, and
+more so in older versions of Perl, the internal encoding shows through.
+To fully understand Perl strings it is necessary to understand these
+implementation details.
+
+This module provides functions to classify a string by encoding and to
+encode a string in a desired way.
+
+This module is implemented in XS, with a pure Perl backup version for
+systems that can't handle XS.
+
+INSTALLATION
+
+ perl Build.PL
+ ./Build
+ ./Build test
+ ./Build install
+
+AUTHOR
+
+Andrew Main (Zefram) <zefram at fysh.org>
+
+COPYRIGHT
+
+Copyright (C) 2009 Andrew Main (Zefram) <zefram at fysh.org>
+
+LICENSE
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
Added: branches/upstream/libscalar-string-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/SIGNATURE?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/SIGNATURE (added)
+++ branches/upstream/libscalar-string-perl/current/SIGNATURE Mon Apr 26 00:26:02 2010
@@ -1,0 +1,38 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.55.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+ % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity. If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 b9cd58d655c5a3be5afea489693de1c552e5c121 .cvsignore
+SHA1 6bac6cb17478948e5adf1a378e8330df9ca75a75 Build.PL
+SHA1 d909d5b32a724160d9b83320fc9480c47134993e Changes
+SHA1 3f24f271d9105fa257dc0ac9773fa57361d0f758 MANIFEST
+SHA1 5c1c0afbc22a47fd9fdb2618b03da4cc2619220d META.yml
+SHA1 684ab827ae5405876abe203f5a032ffa6b575cf7 Makefile.PL
+SHA1 0cd2fd8904b7ff2cba07611af5540c3499dc2478 README
+SHA1 c185a100351b2eb6d840b8ff2ce73c96d154f6a6 lib/Scalar/.cvsignore
+SHA1 9ee6d64702351d9bc817512a76e4a665d7081b66 lib/Scalar/String.pm
+SHA1 3733dbf8563677e245f0cc0d99ed01c80a81b6bd lib/Scalar/String.xs
+SHA1 f36c5928277d92e38d3eb240221dfcfcc6d51cce t/grade.t
+SHA1 438cb548ab97eede0c7f70604f2a33ac4990af10 t/grade_pp.t
+SHA1 0e141eecf3ca4903ef38d9413b5403a9ddb0392f t/pod_cvg.t
+SHA1 74a957cd8b93f25672ecc6aa578a671d084dd343 t/pod_syn.t
+SHA1 3794f0f035dbf2532d7cdd8ab52c8dd3188425ad t/setup_pp.pl
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.9 (GNU/Linux)
+
+iEYEARECAAYFAkm7qxcACgkQOV9mt2VyAVEuewCfcVd6heZuhHMhjnCLw8OoUBfb
+K+kAnikkG7ccO/xXdlsyEK4g+gxkzX+h
+=hBlS
+-----END PGP SIGNATURE-----
Added: branches/upstream/libscalar-string-perl/current/lib/Scalar/.cvsignore
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/lib/Scalar/.cvsignore?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/lib/Scalar/.cvsignore (added)
+++ branches/upstream/libscalar-string-perl/current/lib/Scalar/.cvsignore Mon Apr 26 00:26:02 2010
@@ -1,0 +1,1 @@
+String.c
Added: branches/upstream/libscalar-string-perl/current/lib/Scalar/String.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/lib/Scalar/String.pm?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/lib/Scalar/String.pm (added)
+++ branches/upstream/libscalar-string-perl/current/lib/Scalar/String.pm Mon Apr 26 00:26:02 2010
@@ -1,0 +1,302 @@
+=head1 NAME
+
+Scalar::String - string aspects of scalars
+
+=head1 SYNOPSIS
+
+ use Scalar::String
+ qw(sclstr_is_upgraded sclstr_is_downgraded);
+
+ if(sclstr_is_upgraded($value)) { ...
+ if(sclstr_is_downgraded($value)) { ...
+
+ use Scalar::String qw(
+ sclstr_upgrade_inplace sclstr_upgraded
+ sclstr_downgrade_inplace sclstr_downgraded
+ );
+
+ sclstr_upgrade_inplace($value);
+ $value = sclstr_upgraded($value);
+ sclstr_downgrade_inplace($value);
+ $value = sclstr_downgraded($value);
+
+=head1 DESCRIPTION
+
+This module is about the string part of plain Perl scalars. A scalar has
+a string value, which is notionally a sequence of Unicode codepoints, but
+may be internally encoded in either ISO-8859-1 or UTF-8. In places, and
+more so in older versions of Perl, the internal encoding shows through.
+To fully understand Perl strings it is necessary to understand these
+implementation details.
+
+This module provides functions to classify a string by encoding and to
+encode a string in a desired way.
+
+This module is implemented in XS, with a pure Perl backup version for
+systems that can't handle XS.
+
+=head1 STRING ENCODING
+
+ISO-8859-1 is a simple 8-bit character encoding, which represents the
+first 256 Unicode characters (codepoints 0x00 to 0xff) in one octet each.
+This is how strings were historically represented in Perl. A string
+represented this way is referred to as "downgraded".
+
+UTF-8 is a variable-width character encoding, which represents all
+possible Unicode codepoints in differing numbers of octets. A design
+feature of UTF-8 is that ASCII characters (codepoints 0x00 to 0x7f)
+are each represented in a single octet, identically to their ISO-8859-1
+encoding. Perl has its own variant of UTF-8, which can handle a wider
+range of codepoints than Unicode formally allows. A string represented
+in this variant UTF-8 is referred to as "upgraded".
+
+A Perl string is physically represented as a string of octets along with
+a flag that says whether the string is downgraded or upgraded. At this
+level, to determine the Unicode codepoints that are represented requires
+examining both parts of the representation. If the string contains only
+ASCII characters then the octet sequence is identical in either encoding,
+but Perl still maintains an encoding flag on such a string. A string
+is always either downgraded or upgraded; it is never both or neither.
+
+When handling string input, it is good form to operate only on the Unicode
+characters represented by the string, ignoring the manner in which they
+are encoded. Basic string operations such as concatenation work this way
+(except for a bug in perl 5.6.0), so simple code written in pure Perl is
+generally safe on this front. Pieces of character-based code can pass
+around strings among themselves, and always get consistent behaviour,
+without worrying about the way in which the characters are encoded.
+
+However, due to an historical accident, a lot of C code that interfaces
+with Perl looks at the octets used to represent a string without also
+examining the encoding flag. Such code gives inconsistent behaviour for
+the same character sequence represented in the different ways. In perl
+5.6, many pure Perl operations (such as regular expression matching)
+also work this way, though some of them can be induced to work correctly
+by using the L<utf8> pragma. If perl 5.8, regular expression matching
+is character-based by default, but many I/O functions (such as C<open>)
+are still octet-based.
+
+Where code that operates on the octets of a string must be used by code
+that operates on characters, the latter needs to pay attention to the
+encoding of its strings. Commonly, the octet-based code expects its
+input to be represented in a particular encoding, in which case the
+character-based code must oblige by forcing strings to that encoding
+before they are passed in. There are other usage patterns too.
+
+You will be least confused if you think about a Perl string as a character
+sequence plus an encoding flag. You should normally operate on the
+character sequence and not care about the encoding flag. Occasionally you
+must pay attention to the flag in addition to the characters. Unless you
+are writing C code, you should try not to think about a string the other
+way round, as an octet sequence plus encoding flag.
+
+=cut
+
+package Scalar::String;
+
+use warnings;
+use strict;
+
+our $VERSION = "0.000";
+
+use base "Exporter";
+our @EXPORT_OK = qw(
+ sclstr_is_upgraded sclstr_is_downgraded
+ sclstr_upgrade_inplace sclstr_upgraded
+ sclstr_downgrade_inplace sclstr_downgraded
+);
+
+eval { local $SIG{__DIE__};
+ require XSLoader;
+ XSLoader::load(__PACKAGE__, $VERSION);
+};
+
+if($@ eq "") {
+ close(DATA);
+} else {
+ (my $filename = __FILE__) =~ tr# -~##cd;
+ local $/ = undef;
+ my $pp_code = "#line 128 \"$filename\"\n".<DATA>;
+ close(DATA);
+ {
+ local $SIG{__DIE__};
+ eval $pp_code;
+ }
+ die $@ if $@ ne "";
+}
+
+1;
+
+__DATA__
+
+use Carp qw(croak);
+BEGIN { require utf8 if $] >= 5.008; }
+
+=head1 FUNCTIONS
+
+Each "sclstr_" function takes one or more scalar string arguments to
+operate on. These arguments must be strings; giving non-string arguments
+will cause mayhem. See L<Params::Classify/is_string> for a way to
+check for numericness. Only the string value of the scalar is used;
+the numeric value is completely ignored, so dualvars are not a problem.
+
+=head2 Classification
+
+=over
+
+=item sclstr_is_upgraded(VALUE)
+
+Returns a truth value indicating whether the provided string I<VALUE>
+is in upgraded form.
+
+=cut
+
+sub sclstr_is_upgraded($);
+
+if(defined &utf8::is_utf8) {
+ *sclstr_is_upgraded = sub($) { &utf8::is_utf8 };
+} else {
+ *sclstr_is_upgraded = sub($) {
+ # In perl 5.6, an upgraded string can be detected
+ # (even if it contains no non-ASCII characters) by the
+ # fact that concatenation with it will upgrade another
+ # string. If the probe string contains a non-ASCII
+ # character, its upgrading can be consistently detected
+ # by examining the resulting byte sequence.
+ return unpack("C", "\xaa".$_[0]) != 170;
+ };
+}
+
+=item sclstr_is_downgraded(VALUE)
+
+Returns a truth value indicating whether the provided string I<VALUE>
+is in downgraded form.
+
+=cut
+
+sub sclstr_is_downgraded($) { !&sclstr_is_upgraded }
+
+=back
+
+=head2 Regrading
+
+=over
+
+=item sclstr_upgrade_inplace(VALUE)
+
+Modifies the string I<VALUE> in-place, so that it is in upgraded form,
+regardless of how it was encoded before. The character sequence that
+it represents is unchanged.
+
+A cleaner interface to this operation is the non-mutating
+L</sclstr_upgraded>.
+
+=cut
+
+sub sclstr_upgrade_inplace($);
+
+if($] >= 5.008) {
+ *sclstr_upgrade_inplace = sub($) { &utf8::upgrade };
+} else {
+ # In perl 5.6, upgrade of a string can be forced by
+ # concatenation with an upgraded string.
+ chop(my $upgraded_empty_string = "\x{100}");
+ *sclstr_upgrade_inplace = sub($) { $_[0] .= $upgraded_empty_string; };
+}
+
+=item sclstr_upgraded(VALUE)
+
+Returns a string that represents the same character sequence as the string
+I<VALUE>, and is in upgraded form (regardless of how I<VALUE> is encoded).
+
+=cut
+
+sub sclstr_upgraded($) {
+ my($str) = @_;
+ sclstr_upgrade_inplace($str);
+ return $str;
+}
+
+=item sclstr_downgrade_inplace(VALUE[, FAIL_OK])
+
+Modifies the string I<VALUE> in-place, so that it is in downgraded form,
+regardless of how it was encoded before. The character sequence that it
+represents is unchanged. If the string cannot be downgraded, because it
+contains a non-ISO-8859-1 character, then by default the function C<die>s,
+but if I<FAIL_OK> is present and true then it will return leaving I<VALUE>
+unmodified.
+
+A cleaner interface to this operation is the non-mutating
+L</sclstr_downgraded>.
+
+=cut
+
+sub sclstr_downgrade_inplace($;$);
+
+if($] >= 5.008) {
+ *sclstr_downgrade_inplace = sub($;$) {
+ utf8::downgrade($_[0], $_[1] || 0);
+ };
+} else {
+ # In perl 5.6, there are very few operations that will
+ # downgrade a string. One of the few is regexp submatch
+ # capturing, with the match operator in array context.
+ # Note: retrieving the submatch with $1 will *not*
+ # downgrade.
+ *sclstr_downgrade_inplace = sub($;$) {
+ return unless sclstr_is_upgraded($_[0]);
+ my ($down) = do {
+ use if $] < 5.008, "bytes";
+ $_[0] =~ /\A[\x00-\x7f\x80-\xbf\xc2\xc3]*\z/;
+ } ? do {
+ use if $] < 5.008, "utf8";
+ ($_[0] =~ /\A([\x00-\xff]*)\z/);
+ } : (undef);
+ if(defined $down) {
+ $_[0] = $down;
+ } else {
+ croak "Wide character prevents downgrading"
+ unless $_[1];
+ }
+ };
+}
+
+=item sclstr_downgraded(VALUE[, FAIL_OK])
+
+Returns a string that represents the same character sequence as the
+string I<VALUE>, and is in downgraded form (regardless of how I<VALUE>
+is encoded). If the string cannot be represented in downgraded form,
+because it contains a non-ISO-8859-1 character, then by default the
+function C<die>s, but if I<FAIL_OK> is present and true then it will
+return I<VALUE> in its original upgraded form.
+
+=cut
+
+sub sclstr_downgraded($;$) {
+ my($str, $fail_ok) = @_;
+ sclstr_downgrade_inplace($str, $fail_ok);
+ return $str;
+}
+
+=back
+
+=head1 SEE ALSO
+
+L<utf8>
+
+=head1 AUTHOR
+
+Andrew Main (Zefram) <zefram at fysh.org>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2009 Andrew Main (Zefram) <zefram at fysh.org>
+
+=head1 LICENSE
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
Added: branches/upstream/libscalar-string-perl/current/lib/Scalar/String.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/lib/Scalar/String.xs?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/lib/Scalar/String.xs (added)
+++ branches/upstream/libscalar-string-perl/current/lib/Scalar/String.xs Mon Apr 26 00:26:02 2010
@@ -1,0 +1,62 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+MODULE = Scalar::String PACKAGE = Scalar::String
+
+bool
+sclstr_is_upgraded(SV *value)
+PROTOTYPE: $
+CODE:
+ RETVAL = !!SvUTF8(value);
+OUTPUT:
+ RETVAL
+
+bool
+sclstr_is_downgraded(SV *value)
+PROTOTYPE: $
+CODE:
+ RETVAL = !SvUTF8(value);
+OUTPUT:
+ RETVAL
+
+void
+sclstr_upgrade_inplace(SV *value)
+PROTOTYPE: $
+CODE:
+ sv_utf8_upgrade(value);
+ SvUTF8_on(value);
+
+SV *
+sclstr_upgraded(SV *value)
+PROTOTYPE: $
+CODE:
+ if(SvUTF8(value)) {
+ RETVAL = SvREFCNT_inc(value);
+ } else {
+ RETVAL = newSVsv(value);
+ sv_utf8_upgrade(RETVAL);
+ SvUTF8_on(RETVAL);
+ }
+OUTPUT:
+ RETVAL
+
+void
+sclstr_downgrade_inplace(SV *value, bool fail_ok = 0)
+PROTOTYPE: $;$
+CODE:
+ sv_utf8_downgrade(value, fail_ok);
+
+SV *
+sclstr_downgraded(SV *value, bool fail_ok = 0)
+PROTOTYPE: $;$
+CODE:
+ if(!SvUTF8(value)) {
+ RETVAL = SvREFCNT_inc(value);
+ } else {
+ RETVAL = sv_mortalcopy(value);
+ sv_utf8_downgrade(RETVAL, fail_ok);
+ SvREFCNT_inc(RETVAL);
+ }
+OUTPUT:
+ RETVAL
Added: branches/upstream/libscalar-string-perl/current/t/grade.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/t/grade.t?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/t/grade.t (added)
+++ branches/upstream/libscalar-string-perl/current/t/grade.t Mon Apr 26 00:26:02 2010
@@ -1,0 +1,102 @@
+use warnings;
+use strict;
+
+use Test::More tests => 1 + 31*4 + 31*4 + 14*20;
+
+use_ok "Scalar::String", qw(
+ sclstr_is_upgraded sclstr_is_downgraded
+ sclstr_upgrade_inplace sclstr_downgrade_inplace
+ sclstr_upgraded sclstr_downgraded
+);
+
+foreach my $tstr (
+ "",
+ "abc",
+ "a\x00b\x7fc",
+ "a"x40000,
+) {
+ my @u = (sclstr_upgraded($tstr));
+ my @d = (sclstr_downgraded($tstr));
+ push @u, map { sclstr_upgraded($_) } $u[0], $d[0];
+ push @u, map { my $s = $_; sclstr_upgrade_inplace($s); $s }
+ $u[0], $d[0];
+ push @d, map { my $s = $_; sclstr_downgrade_inplace($s); $s }
+ $u[0], $d[0];
+ push @d, map { sclstr_downgraded($_) } $u[0], $d[0];
+ foreach(@u) {
+ ok sclstr_is_upgraded($_);
+ ok !sclstr_is_downgraded($_);
+ ok $_ eq $u[0];
+ }
+ foreach(@d) {
+ ok !sclstr_is_upgraded($_);
+ ok sclstr_is_downgraded($_);
+ ok $_ eq $d[0];
+ }
+ ok $u[0] eq $d[0];
+}
+
+foreach my $tstr (
+ "\xc2\x80",
+ "\x80abc\xff",
+ "\xffabc\x80",
+ ("a"x40000)."\x80",
+) {
+ my @u = (sclstr_upgraded($tstr));
+ my @d = (sclstr_downgraded($tstr));
+ push @u, map { sclstr_upgraded($_) } $u[0], $d[0];
+ push @d, map { sclstr_downgraded($_) } $u[0], $d[0];
+ push @u, map { my $s = $_; sclstr_upgrade_inplace($s); $s }
+ $u[0], $d[0];
+ push @d, map { my $s = $_; sclstr_downgrade_inplace($s); $s }
+ $u[0], $d[0];
+ foreach(@u) {
+ ok sclstr_is_upgraded($_);
+ ok !sclstr_is_downgraded($_);
+ ok $_ eq $u[0];
+ }
+ foreach(@d) {
+ ok !sclstr_is_upgraded($_);
+ ok sclstr_is_downgraded($_);
+ ok $_ eq $d[0];
+ }
+ ok ord($u[0]) == ord($d[0]);
+}
+
+no warnings "utf8";
+foreach my $tstr (
+ "abc\x{100}xyz",
+ "abc\x{d7ff}xyz",
+ "abc\x{d800}xyz",
+ "abc\x{dfff}xyz",
+ "abc\x{e000}xyz",
+ "abc\x{fdd0}xyz",
+ "abc\x{fffd}xyz",
+ "abc\x{fffe}xyz",
+ "abc\x{ffff}xyz",
+ "abc\x{10000}xyz",
+ "abc\x{1fffd}xyz",
+ "abc\x{1fffe}xyz",
+ "abc\x{1ffff}xyz",
+ "abc\x{20000}xyz",
+ "abc\x{10fffd}xyz",
+ "abc\x{10fffe}xyz",
+ "abc\x{10ffff}xyz",
+ "abc\x{110000}xyz",
+ "abc\x{7fffffff}xyz",
+ ("a"x40000)."\x{100}",
+) {
+ my @u = ($tstr);
+ push @u, sclstr_upgraded($u[0]);
+ eval { sclstr_downgraded($u[0]) }; isnt $@, "";
+ eval { sclstr_downgrade_inplace($u[0]) }; isnt $@, "";
+ push @u, sclstr_downgraded($u[0], 1);
+ push @u, do { my $s = $u[0]; sclstr_downgrade_inplace($s, 1); $s };
+ foreach(@u) {
+ ok sclstr_is_upgraded($_);
+ ok !sclstr_is_downgraded($_);
+ ok $_ eq $u[0];
+ }
+}
+
+1;
Added: branches/upstream/libscalar-string-perl/current/t/grade_pp.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/t/grade_pp.t?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/t/grade_pp.t (added)
+++ branches/upstream/libscalar-string-perl/current/t/grade_pp.t Mon Apr 26 00:26:02 2010
@@ -1,0 +1,7 @@
+use warnings;
+use strict;
+
+do "t/setup_pp.pl" or die $@ || $!;
+do "t/grade.t" or die $@ || $!;
+
+1;
Added: branches/upstream/libscalar-string-perl/current/t/pod_cvg.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/t/pod_cvg.t?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/t/pod_cvg.t (added)
+++ branches/upstream/libscalar-string-perl/current/t/pod_cvg.t Mon Apr 26 00:26:02 2010
@@ -1,0 +1,4 @@
+use Test::More;
+plan skip_all => "Test::Pod::Coverage not available"
+ unless eval "use Test::Pod::Coverage; 1";
+Test::Pod::Coverage::all_pod_coverage_ok();
Added: branches/upstream/libscalar-string-perl/current/t/pod_syn.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/t/pod_syn.t?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/t/pod_syn.t (added)
+++ branches/upstream/libscalar-string-perl/current/t/pod_syn.t Mon Apr 26 00:26:02 2010
@@ -1,0 +1,3 @@
+use Test::More;
+plan skip_all => "Test::Pod not available" unless eval "use Test::Pod 1.00; 1";
+Test::Pod::all_pod_files_ok();
Added: branches/upstream/libscalar-string-perl/current/t/setup_pp.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscalar-string-perl/current/t/setup_pp.pl?rev=56887&op=file
==============================================================================
--- branches/upstream/libscalar-string-perl/current/t/setup_pp.pl (added)
+++ branches/upstream/libscalar-string-perl/current/t/setup_pp.pl Mon Apr 26 00:26:02 2010
@@ -1,0 +1,11 @@
+require XSLoader;
+
+my $orig_load = \&XSLoader::load;
+no warnings "redefine";
+*XSLoader::load = sub {
+ die "XS loading disabled for Scalar::String"
+ if $_[0] eq "Scalar::String";
+ goto &$orig_load;
+};
+
+1;
More information about the Pkg-perl-cvs-commits
mailing list