.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "B::COW 3" .TH B::COW 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME B::COW \- B::COW additional B helpers to check COW status .SH VERSION .IX Header "VERSION" version 0.007 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& #!perl \& \& use strict; \& use warnings; \& \& use Test::More; # just used for illustration purpose \& \& use B::COW qw{:all}; \& \& if ( can_cow() ) { # $] >= 5.020 \& ok !is_cow(undef); \& \& my $str = "abcdef"; \& ok is_cow($str); \& is cowrefcnt($str), 1; \& \& my @a; \& push @a, $str for 1 .. 100; \& \& ok is_cow($str); \& ok is_cow( $a[0] ); \& ok is_cow( $a[99] ); \& is cowrefcnt($str), 101; \& is cowrefcnt( $a[\-1] ), 101; \& \& delete $a[99]; \& is cowrefcnt($str), 100; \& is cowrefcnt( $a[\-1] ), 100; \& \& { \& my %h = ( \*(Aqa\*(Aq .. \*(Aqd\*(Aq ); \& foreach my $k ( sort keys %h ) { \& ok is_cow($k); \& is cowrefcnt($k), 0; \& } \& } \& \& } \& else { \& my $str = "abcdef"; \& is is_cow($str), undef; \& is cowrefcnt($str), undef; \& is cowrefcnt_max(), undef; \& } \& \& done_testing; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" B::COW provides some naive additional B helpers to check the COW status of one SvPV. .SS "COW or Copy On Write introduction" .IX Subsection "COW or Copy On Write introduction" A COWed SvPV is sharing its string (the PV) with other SvPVs. It's a (kind of) Read Only C string, that would be Copied On Write (COW). .PP More than one SV can share the same PV, but when one PV need to alter it, it would perform a copy of it, decrease the COWREFCNT counter. .PP One SV can then drop the COW flag when it's the only one holding a pointer to the PV. .PP The COWREFCNT is stored at the end of the PV, after the the "\e0". .PP That value is limited to 255, when we reach 255, a new PV would be created, .SH FUNCTIONS .IX Header "FUNCTIONS" .SS \fBcan_cow()\fP .IX Subsection "can_cow()" Return a boolean value. True if your Perl version support Copy On Write for SvPVs .SS "is_cow( PV )" .IX Subsection "is_cow( PV )" Return a boolean value. True if the SV is cowed SvPV. (check the SV FLAGS) .SS "cowrefcnt( PV )" .IX Subsection "cowrefcnt( PV )" Return one integer representing the COW RefCount value. If the string is not COW, then it will return undef. .SS \fBcowrefcnt_max()\fP .IX Subsection "cowrefcnt_max()" Will return the SV_COW_REFCNT_MAX of your Perl. (if COW is supported, this should be 255 unless customized). .SH AUTHOR .IX Header "AUTHOR" Nicolas R. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2018 by Nicolas R. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.