File Coverage

blib/lib/String/Gsub.pm
Criterion Covered Total %
statement 39 39 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 7 7 100.0
total 58 58 100.0


line stmt bran cond sub pod time code
1             ## ----------------------------------------------------------------------------
2             # String::Gsub
3             # -----------------------------------------------------------------------------
4             # Mastering programmed by YAMASHINA Hio
5             #
6             # Copyright 2006 YAMASHINA Hio
7             # -----------------------------------------------------------------------------
8             # $Id$
9             # -----------------------------------------------------------------------------
10             package String::Gsub;
11 3     3   74164 use warnings;
  3         7  
  3         96  
12 3     3   17 use strict;
  3         6  
  3         101  
13              
14 3     3   1526 use String::Gsub::Functions;
  3         7  
  3         243  
15 3     3   17 use base qw(Exporter);
  3         6  
  3         495  
16 3     3   18 use overload q|""| => \&stringy;
  3         5  
  3         17  
17             our @EXPORT_OK = qw(gstr);
18              
19             our $VERSION = '0.04';
20              
21              
22             1;
23              
24             # -----------------------------------------------------------------------------
25             # gstr($str).
26             #
27             sub gstr($)
28             {
29 26     26 1 2330 __PACKAGE__->new(shift);
30             }
31              
32             # -----------------------------------------------------------------------------
33             # $pkg->new($str).
34             #
35             sub new
36             {
37 26     26 1 41 my $pkg = shift;
38 26         44 my $str = shift;
39 26         147 bless {s=>$str}, $pkg;
40             }
41              
42             # -----------------------------------------------------------------------------
43             # $gstr->gsubx($regex, $replacement);
44             # $regex is qr// or "string".
45             # $replacement is sub{} or "string".
46             #
47             sub gsubx
48             {
49 2     2 1 18 my $this = shift;
50 2         4 my $re = shift;
51 2         5 my $sub = shift;
52            
53 2         12 &String::Gsub::Functions::gsubx($this->{s}, $re, $sub, @_);
54 2         6 $this;
55             }
56              
57             # -----------------------------------------------------------------------------
58             # $gstr->gsub($regex, $replacement);
59             # $regex is qr// or "string".
60             # $replacement is sub{} or "string".
61             #
62             sub gsub
63             {
64 9     9 1 850 my $this = shift;
65 9         14 my $re = shift;
66 9         15 my $sub = shift;
67            
68 9         167 gstr(&String::Gsub::Functions::gsub($this->{s}, $re, $sub, @_));
69             }
70              
71             # -----------------------------------------------------------------------------
72             # $gstr->subx($regex, $replacement);
73             # $regex is qr// or "string".
74             # $replacement is sub{} or "string".
75             #
76             sub subx
77             {
78 2     2 1 20 my $this = shift;
79 2         4 my $re = shift;
80 2         4 my $sub = shift;
81            
82 2         13 &String::Gsub::Functions::subsx($this->{s}, $re, $sub, @_);
83 2         8 $this;
84             }
85              
86             # -----------------------------------------------------------------------------
87             # $gstr->sub($regex, $replacement);
88             # $regex is qr// or "string".
89             # $replacement is sub{} or "string".
90             #
91             sub sub
92             {
93 4     4 1 921 my $this = shift;
94 4         6 my $re = shift;
95 4         8 my $sub = shift;
96            
97 4         19 gstr(&String::Gsub::Functions::subs($this->{s}, $re, $sub, @_));
98             }
99              
100             # -----------------------------------------------------------------------------
101             # $gstr->stringy()
102             # return string contained in.
103             #
104             sub stringy
105             {
106 39     39 1 60907 my $this = shift;
107 39         2537 $this->{s};
108             }
109              
110             __END__