Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/perlonjava/core/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class Configuration {
* Automatically populated by Gradle/Maven during build.
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String gitCommitId = "ff1da2bbb";
public static final String gitCommitId = "775a74956";

/**
* Git commit date of the build (ISO format: YYYY-MM-DD).
Expand All @@ -48,7 +48,7 @@ public final class Configuration {
* Parsed by App::perlbrew and other tools via: perl -V | grep "Compiled at"
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String buildTimestamp = "Apr 29 2026 13:59:18";
public static final String buildTimestamp = "Apr 29 2026 15:16:52";

// Prevent instantiation
private Configuration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,12 @@ public RuntimeArray values() {
}
isKey = !isKey;
}
hashIterator = null; // keys resets the iterator
hashIterator = null; // values resets the iterator
// Set scalarContextSize so that values() in scalar context returns the count.
// Without this, when `values %h` is the last expression of a sub called in
// scalar context, getList() copies the elements into a RuntimeList whose
// scalar() yields the LAST element instead of the count.
list.scalarContextSize = list.elements.size();
return list;
}

Expand All @@ -936,6 +941,8 @@ public RuntimeArray values() {
list.elements.add(value); // push an alias to the value (direct reference, not a copy)
}
hashIterator = null; // values resets the iterator
// Mirror keys(): mark this array so scalar context returns the count, not the last value.
list.scalarContextSize = list.elements.size();
return list;
}

Expand Down
78 changes: 78 additions & 0 deletions src/main/perl/lib/Unicode/GCString.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package Unicode::GCString;

# Minimal pure-Perl shim of Unicode::GCString for PerlOnJava.
#
# The original module is part of the XS-based Unicode::LineBreak
# distribution and provides a grapheme-cluster string API. PerlOnJava
# ships only the tiny subset of GCString that downstream modules
# (String::Print, Text::vCard, ...) actually use.
#
# If a CPAN install of Unicode::LineBreak would otherwise overwrite
# this file with the XS-needing version, MakeMaker.pm in PerlOnJava
# detects the bundled copy in jar:PERL5LIB/Unicode/GCString.pm and
# skips it, preserving this shim.
#
# If you need the full functionality, please open an issue.

use strict;
use warnings;

our $VERSION = '2019.001';

sub new {
my ($class, $str) = @_;
$str = '' unless defined $str;
my @clusters = ($str =~ /(\X)/gs);
return bless { str => $str, clusters => \@clusters }, $class;
}

sub length { return scalar @{ $_[0]->{clusters} }; }

sub as_string { return $_[0]->{str}; }

sub substr {
my ($self, $start, $len) = @_;
my @c = @{ $self->{clusters} };
my $total = scalar @c;
$start = 0 if !defined $start;
if ($start < 0) { $start = $total + $start; }
$start = 0 if $start < 0;
$start = $total if $start > $total;
my $end;
if (!defined $len) {
$end = $total;
} elsif ($len < 0) {
$end = $total + $len;
} else {
$end = $start + $len;
}
$end = $start if $end < $start;
$end = $total if $end > $total;
my $piece = join '', @c[$start .. $end - 1];
return Unicode::GCString->new($piece);
}

# Approximate column width (1 per grapheme cluster).
sub columns { return scalar @{ $_[0]->{clusters} }; }

use overload
'""' => \&as_string,
'bool' => sub { CORE::length( $_[0]->{str} ) > 0 },
'0+' => \&length,
fallback => 1;

1;

__END__

=head1 NAME

Unicode::GCString - Minimal PerlOnJava shim

=head1 DESCRIPTION

Provides just enough of L<Unicode::GCString> for modules like
L<String::Print> and L<Text::vCard> that only need basic grapheme
cluster splitting.

=cut
60 changes: 9 additions & 51 deletions src/main/perl/lib/Unicode/LineBreak.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,15 @@ sub break {
return defined $str ? $str : '';
}

package Unicode::GCString;

# Minimal grapheme-cluster string class. Uses \X to split the string
# into grapheme clusters. Only the methods used by Text::vCard et al
# are implemented: new, length, substr, as_string, columns.

use strict;
use warnings;

sub new {
my ($class, $str) = @_;
$str = '' unless defined $str;
my @clusters = ($str =~ /(\X)/gs);
return bless { str => $str, clusters => \@clusters }, $class;
}

sub length { return scalar @{ $_[0]->{clusters} }; }

sub as_string { return $_[0]->{str}; }

# String overload would be nice, but keep it explicit.
sub substr {
my ($self, $start, $len) = @_;
my @c = @{ $self->{clusters} };
my $total = scalar @c;
$start = 0 if !defined $start;
if ($start < 0) { $start = $total + $start; }
$start = 0 if $start < 0;
$start = $total if $start > $total;
my $end;
if (!defined $len) {
$end = $total;
} elsif ($len < 0) {
$end = $total + $len;
} else {
$end = $start + $len;
}
$end = $start if $end < $start;
$end = $total if $end > $total;
my $piece = join '', @c[$start .. $end - 1];
return Unicode::GCString->new($piece);
}

# Approximate column width (1 per grapheme cluster).
sub columns { return scalar @{ $_[0]->{clusters} }; }

use overload
'""' => \&as_string,
'bool' => sub { CORE::length( $_[0]->{str} ) > 0 },
'0+' => \&length,
fallback => 1;
# The Unicode::GCString package now lives in its own file
# (lib/Unicode/GCString.pm) so that:
# * `use Unicode::GCString` works without first loading
# Unicode::LineBreak (e.g. String::Print does this);
# * the MakeMaker SKIP-bundled-file logic detects
# jar:PERL5LIB/Unicode/GCString.pm and refuses to overwrite the
# pure-Perl shim with the XS-needing version from CPAN's
# Unicode-LineBreak distribution.
require Unicode::GCString;

1;

Expand Down
Loading