.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 3pm" .TH B::COW 3pm "2020-11-08" "perl v5.32.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.004 .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 \s-1COW\s0 status of one SvPV. .SS "\s-1COW\s0 or Copy On Write introduction" .IX Subsection "COW or Copy On Write introduction" A COWed SvPV is sharing its string (the \s-1PV\s0) with other SvPVs. It's a (kind of) Read Only C string, that would be Copied On Write (\s-1COW\s0). .PP More than one \s-1SV\s0 can share the same \s-1PV,\s0 but when one \s-1PV\s0 need to alter it, it would perform a copy of it, decrease the \s-1COWREFCNT\s0 counter. .PP One \s-1SV\s0 can then drop the \s-1COW\s0 flag when it's the only one holding a pointer to the \s-1PV.\s0 .PP The \s-1COWREFCNT\s0 is stored at the end of the \s-1PV,\s0 after the the \*(L"\e0\*(R". .PP That value is limited to 255, when we reach 255, a new \s-1PV\s0 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( \s-1PV\s0 )" .IX Subsection "is_cow( PV )" Return a boolean value. True if the \s-1SV\s0 is cowed SvPV. (check the \s-1SV FLAGS\s0) .SS "cowrefcnt( \s-1PV\s0 )" .IX Subsection "cowrefcnt( PV )" Return one integer representing the \s-1COW\s0 RefCount value. If the string is not \s-1COW,\s0 then it will return undef. .SS "\fBcowrefcnt_max()\fP" .IX Subsection "cowrefcnt_max()" Will return the \s-1SV_COW_REFCNT_MAX\s0 of your Perl. (if \s-1COW\s0 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.