Bubblegum
view release on metacpan or search on metacpan
lib/Bubblegum/Object/String.pm view on Meta::CPAN
# ABSTRACT: Common Methods for Operating on Strings
package Bubblegum::Object::String;
use 5.10.0;
use namespace::autoclean;
use Bubblegum::Class 'with';
use Bubblegum::Constraints -isas, -types;
use Carp 'confess';
use Scalar::Util 'looks_like_number';
with 'Bubblegum::Object::Role::Defined';
with 'Bubblegum::Object::Role::Comparison';
with 'Bubblegum::Object::Role::Coercive';
with 'Bubblegum::Object::Role::Value';
our @ISA = (); # non-object
our $VERSION = '0.45'; # VERSION
sub append {
return $_[0] = CORE::join ' ', map type_string($_), @_;
}
sub codify {
my $self = CORE::shift || 'return(@_)';
my $vars = sprintf 'my (%s) = @_;', join ',', map "\$$_", 'a'..'z';
my $code = sprintf 'use gum; sub { %s return do { %s } }', $vars, $self;
my $ref = eval $code or confess $@;
return $ref;
}
sub concat {
return $_[0] = CORE::join '', map type_string($_), @_;
}
sub contains {
my $self = CORE::shift;
my $other = CORE::shift;
if (isa_regexpref($other)) {
return $self =~ $other ? 1 : 0;
}
if (isa_string($other)) {
return CORE::index($self, $other) < 0 ? 0 : 1;
}
return 0;
}
sub eq {
my $self = CORE::shift;
my $other = type_string CORE::shift;
return $self eq $other ? 1 : 0;
}
sub eqtv {
my $self = CORE::shift;
my $other = CORE::shift;
return 0 unless CORE::defined $other;
return ($self->type eq $other->type && $self eq $other) ? 1 : 0;
( run in 0.621 second using v1.01-cache-2.11-cpan-f56aa216473 )