1B::COW(3)             User Contributed Perl Documentation            B::COW(3)
2
3
4

NAME

6       B::COW - B::COW additional B helpers to check COW status
7

VERSION

9       version 0.004
10

SYNOPSIS

12        #!perl
13
14        use strict;
15        use warnings;
16
17        use Test::More;    # just used for illustration purpose
18
19        use B::COW qw{:all};
20
21        if ( can_cow() ) {    # $] >= 5.020
22            ok !is_cow(undef);
23
24            my $str = "abcdef";
25            ok is_cow($str);
26            is cowrefcnt($str), 1;
27
28            my @a;
29            push @a, $str for 1 .. 100;
30
31            ok is_cow($str);
32            ok is_cow( $a[0] );
33            ok is_cow( $a[99] );
34            is cowrefcnt($str), 101;
35            is cowrefcnt( $a[-1] ), 101;
36
37            delete $a[99];
38            is cowrefcnt($str), 100;
39            is cowrefcnt( $a[-1] ), 100;
40
41            {
42                my %h = ( 'a' .. 'd' );
43                foreach my $k ( sort keys %h ) {
44                    ok is_cow($k);
45                    is cowrefcnt($k), 0;
46                }
47            }
48
49        }
50        else {
51            my $str = "abcdef";
52            is is_cow($str),    undef;
53            is cowrefcnt($str), undef;
54            is cowrefcnt_max(), undef;
55        }
56
57        done_testing;
58

DESCRIPTION

60       B::COW provides some naive additional B helpers to check the COW status
61       of one SvPV.
62
63   COW or Copy On Write introduction
64       A COWed SvPV is sharing its string (the PV) with other SvPVs.  It's a
65       (kind of) Read Only C string, that would be Copied On Write (COW).
66
67       More than one SV can share the same PV, but when one PV need to alter
68       it, it would perform a copy of it, decrease the COWREFCNT counter.
69
70       One SV can then drop the COW flag when it's the only one holding a
71       pointer to the PV.
72
73       The COWREFCNT is stored at the end of the PV, after the the "\0".
74
75       That value is limited to 255, when we reach 255, a new PV would be
76       created,
77

FUNCTIONS

79   can_cow()
80       Return a boolean value. True if your Perl version support Copy On Write
81       for SvPVs
82
83   is_cow( PV )
84       Return a boolean value. True if the SV is cowed SvPV. (check the SV
85       FLAGS)
86
87   cowrefcnt( PV )
88       Return one integer representing the COW RefCount value.  If the string
89       is not COW, then it will return undef.
90
91   cowrefcnt_max()
92       Will return the SV_COW_REFCNT_MAX of your Perl. (if COW is supported,
93       this should be 255 unless customized).
94

AUTHOR

96       Nicolas R. <atoomic@cpan.org>
97
99       This software is copyright (c) 2018 by Nicolas R.
100
101       This is free software; you can redistribute it and/or modify it under
102       the same terms as the Perl 5 programming language system itself.
103
104
105
106perl v5.32.0                      2020-07-28                         B::COW(3)
Impressum