NAME

Data::Object::String

ABSTRACT

String Class for Perl 5

SYNOPSIS

package main;

use Data::Object::String;

my $string = Data::Object::String->new('abcedfghi');

DESCRIPTION

This package provides methods for manipulating string data.

INHERITS

This package inherits behaviors from:

Data::Object::Kind

INTEGRATES

This package integrates behaviors from:

Data::Object::Role::Dumpable

Data::Object::Role::Proxyable

Data::Object::Role::Throwable

LIBRARIES

This package uses type constraints from:

Data::Object::Types

METHODS

This package implements the following methods:

append

append() : Str

The append method appends arugments to the string using spaces.

append example #1
my $string = Data::Object::String->new('firstname');

$string->append('lastname'); # firstname lastname

camelcase

camelcase() : Str

The camelcase method converts the string to camelcase.

camelcase example #1
my $string = Data::Object::String->new('hello world');

$string->camelcase; # HelloWorld

chomp

chomp() : Str

The chomp method removes the newline (or the current value of $/) from the end of the string.

chomp example #1
my $string = Data::Object::String->new("name, age, dob, email\n");

$string->chomp; # name, age, dob, email

chop

chop() : Str

The chop method removes and returns the last character of the string.

chop example #1
my $string = Data::Object::String->new("this is just a test.");

$string->chop; # this is just a test

concat

concat(Any $arg1) : Str

The concat method returns the string with the argument list appended to it.

concat example #1
my $string = Data::Object::String->new('ABC');

$string->concat('DEF', 'GHI'); # ABCDEFGHI

contains

contains(Str | RegexpRef $arg1) : Num

The contains method searches the string for a substring or expression returns true or false if found.

contains example #1
my $string = Data::Object::String->new('Nullam ultrices placerat.');

$string->contains('trices'); # 1
contains example #2
my $string = Data::Object::String->new('Nullam ultrices placerat.');

$string->contains('itrices'); # 0
contains example #3
my $string = Data::Object::String->new('Nullam ultrices placerat.');

$string->contains(qr/trices/); # 1
contains example #4
my $string = Data::Object::String->new('Nullam ultrices placerat.');

$string->contains(qr/itrices/); # 0

defined

defined() : Num

The defined method returns true, always.

defined example #1
my $string = Data::Object::String->new();

$string->defined; # 1

eq

eq(Any $arg1) : Num

The eq method returns true if the argument provided is equal to the string.

eq example #1
my $string = Data::Object::String->new('exciting');

$string->eq('Exciting'); # 0

ge

ge(Any $arg1) : Num

The ge method returns true if the argument provided is greater-than or equal-to the string.

ge example #1
my $string = Data::Object::String->new('exciting');

$string->ge('Exciting'); # 1

gt

gt(Any $arg1) : Num

The gt method returns true if the argument provided is greater-than the string.

gt example #1
my $string = Data::Object::String->new('exciting');

$string->gt('Exciting'); # 1

hex

hex() : Str

The hex method returns the value resulting from interpreting the string as a hex string.

hex example #1
my $string = Data::Object::String->new('0xaf');

$string->hex; # 175

index

index(Str $arg1, Num $arg2) : Num

The index method searches for the argument within the string and returns the position of the first occurrence of the argument.

index example #1
my $string = Data::Object::String->new('unexplainable');

$string->index('explain'); # 2
index example #2
my $string = Data::Object::String->new('unexplainable');

$string->index('explain', 0); # 2
index example #3
my $string = Data::Object::String->new('unexplainable');

$string->index('explain', 1); # 2
index example #4
my $string = Data::Object::String->new('unexplainable');

$string->index('explain', 2); # 2
index example #5
my $string = Data::Object::String->new('unexplainable');

$string->index('explained'); # -1

lc

lc() : Str

The lc method returns a lowercased version of the string.

lc example #1
my $string = Data::Object::String->new('EXCITING');

$string->lc; # exciting

lcfirst

lcfirst() : Str

The lcfirst method returns a the string with the first character lowercased.

lcfirst example #1
my $string = Data::Object::String->new('EXCITING');

$string->lcfirst; # eXCITING

le

le(Any $arg1) : Num

The le method returns true if the argument provided is less-than or equal-to the string.

le example #1
my $string = Data::Object::String->new('exciting');

$string->le('Exciting'); # 0

length

length() : Num

The length method returns the number of characters within the string.

length example #1
my $string = Data::Object::String->new('longggggg');

$string->length; # 9

lines

lines() : ArrayRef

The lines method returns an arrayref of parts by splitting on 1 or more newline characters.

lines example #1
my $string = Data::Object::String->new(
  "who am i?\nwhere am i?\nhow did I get here"
);

$string->lines; # ['who am i?','where am i?','how did I get here']

lowercase

lowercase() : Str

The lowercase method is an alias to the lc method.

lowercase example #1
my $string = Data::Object::String->new('EXCITING');

$string->lowercase; # exciting

lt

lt(Any $arg1) : Num

The lt method returns true if the argument provided is less-than the string.

lt example #1
my $string = Data::Object::String->new('exciting');

$string->lt('Exciting'); # 0

ne

ne(Any $arg1) : Num

The ne method returns true if the argument provided is not equal to the string.

ne example #1
my $string = Data::Object::String->new('exciting');

$string->ne('Exciting'); # 1

render

render(HashRef $arg1) : Str

The render method treats the string as a template and performs a simple token replacement using the argument provided.

render example #1
my $string = Data::Object::String->new('Hi, {name}!');

$string->render({name => 'Friend'}); # Hi, Friend!

replace

replace(Str $arg1, Str $arg2) : Str

The replace method performs a search and replace operation and returns the modified string.

replace example #1
my $string = Data::Object::String->new('Hello World');

$string->replace('World', 'Universe'); # Hello Universe
replace example #2
my $string = Data::Object::String->new('Hello World');

$string->replace('world', 'Universe', 'i'); # Hello Universe
replace example #3
my $string = Data::Object::String->new('Hello World');

$string->replace(qr/world/i, 'Universe'); # Hello Universe
replace example #4
my $string = Data::Object::String->new('Hello World');

$string->replace(qr/.*/, 'Nada'); # Nada

reverse

reverse() : Str

The reverse method returns a string where the characters in the string are in the opposite order.

reverse example #1
my $string = Data::Object::String->new('dlrow ,olleH');

$string->reverse; # Hello, world

rindex

rindex(Str $arg1, Num $arg2) : Num

The rindex method searches for the argument within the string and returns the position of the last occurrence of the argument.

rindex example #1
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain'); # 14
rindex example #10
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explained'); # -1
rindex example #2
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 0); # 0
rindex example #3
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 21); # 14
rindex example #4
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 22); # 14
rindex example #5
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 23); # 14
rindex example #6
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 20); # 14
rindex example #7
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 14); # 0
rindex example #8
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 13); # 0
rindex example #9
my $string = Data::Object::String->new('explain the unexplainable');

$string->rindex('explain', 0); # 0

snakecase

snakecase() : Str

The snakecase method converts the string to snakecase.

snakecase example #1
my $string = Data::Object::String->new('hello world');

$string->snakecase; # hello_world

split

split(RegexpRef $arg1, Num $arg2) : ArrayRef

The split method returns an arrayref by splitting on the argument.

split example #1
my $string = Data::Object::String->new('name, age, dob, email');

$string->split(', '); # ['name', 'age', 'dob', 'email']
split example #2
my $string = Data::Object::String->new('name, age, dob, email');

$string->split(', ', 2); # ['name', 'age, dob, email']
split example #3
my $string = Data::Object::String->new('name, age, dob, email');

$string->split(qr/\,\s*/); # ['name', 'age', 'dob', 'email']
split example #4
my $string = Data::Object::String->new('name, age, dob, email');

$string->split(qr/\,\s*/, 2); # ['name', 'age, dob, email']

strip

strip() : Str

The strip method returns the string replacing occurences of 2 or more whitespaces with a single whitespace.

strip example #1
my $string = Data::Object::String->new('one,  two,  three');

$string->strip; # one, two, three

titlecase

titlecase() : Str

The titlecase method returns the string capitalizing the first character of each word.

titlecase example #1
my $string = Data::Object::String->new('mr. john doe');

$string->titlecase; # Mr. John Doe

trim

trim() : Str

The trim method removes one or more consecutive leading and/or trailing spaces from the string.

trim example #1
my $string = Data::Object::String->new('   system is   ready   ');

$string->trim; # system is   ready

uc

uc() : Str

The uc method returns an uppercased version of the string.

uc example #1
my $string = Data::Object::String->new('exciting');

$string->uc; # EXCITING

ucfirst

ucfirst() : Str

The ucfirst method returns a the string with the first character uppercased.

ucfirst example #1
my $string = Data::Object::String->new('exciting');

$string->ucfirst; # Exciting

uppercase

uppercase() : Str

The uppercase method is an alias to the uc method.

uppercase example #1
my $string = Data::Object::String->new('exciting');

$string->uppercase; # EXCITING

words

words() : ArrayRef

The words method returns an arrayref by splitting on 1 or more consecutive spaces.

words example #1
my $string = Data::Object::String->new(
  'is this a bug we\'re experiencing'
);

$string->words; # ["is","this","a","bug","we're","experiencing"]

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues