GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::Object::String(3) User Contributed Perl Documentation Data::Object::String(3)

Data::Object::String

String Class for Perl 5

  package main;

  use Data::Object::String;

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

This package provides methods for manipulating string data.

This package inherits behaviors from:

Data::Object::Kind

This package integrates behaviors from:

Data::Object::Role::Dumpable

Data::Object::Role::Proxyable

Data::Object::Role::Throwable

This package uses type constraints from:

Data::Object::Types

This package implements the following methods:

  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() : Str

The camelcase method converts the string to camelcase.

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

  $string->camelcase; # HelloWorld
    

  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() : 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(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(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() : Num

The defined method returns true, always.

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

  $string->defined; # 1
    

  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(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(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() : 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(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() : 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() : 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(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() : 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() : 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() : 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(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(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(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(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() : 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(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() : 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(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() : 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() : 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() : 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() : 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() : 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() : 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() : 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"]
    

Al Newkirk, "awncorp@cpan.org"

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" <https://github.com/iamalnewkirk/data-object/blob/master/LICENSE>.

Wiki <https://github.com/iamalnewkirk/data-object/wiki>

Project <https://github.com/iamalnewkirk/data-object>

Initiatives <https://github.com/iamalnewkirk/data-object/projects>

Milestones <https://github.com/iamalnewkirk/data-object/milestones>

Contributing <https://github.com/iamalnewkirk/data-object/blob/master/CONTRIBUTE.md>

Issues <https://github.com/iamalnewkirk/data-object/issues>

2020-04-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.