B::COW(3)
β¨ NAME β¨
okay so bestie, this is the B::COW(3) page from User Contributed Perl Documentation β the manual for B::COW. The name is literally: B::COW β B::COW additional B helpers to check COW status. That's the whole name, and it's giving βsmall module, big COW energy.β π
π VERSION π
version 0.007
πΈ SYNOPSIS πΈ
bestie, here's the synopsis exactly as it appears, no cap:
#!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 = ( 'a' .. 'd' );
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;
π¦ DESCRIPTION π¦
B::COW provides some naive additional B helpers to check the COW status of one SvPV. naive is the module's word, not mine β we respect the lore. π
π 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). That's the whole plot, and it's honestly iconic.
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. So yes, the counter goes down as part of the COW behavior.
One SV can then drop the COW flag when it's the only one holding a pointer to the PV.
The COWREFCNT is stored at the end of the PV, after the "\0". That value is limited to 255; when we reach 255, a new PV would be created. that 255 cap is real, bestie β do not sleep on it. π
π FUNCTIONS π
okay, the actual helpers β these are the little guys you call. π«Ά
β¨ can_cow()
Return a boolean value. True if your Perl version support Copy On Write for SvPVs. So it's basically a vibe check for whether COW is available. π
π is_cow( PV )
Return a boolean value. True if the SV is cowed SvPV. (check the SV FLAGS). So yes, the SV FLAGS are the main character here. β
π cowrefcnt( PV )
Return one integer representing the COW RefCount value. If the string is not COW, then it will return undef. one integer, no vibes, just a count.
π cowrefcnt_max()
Will return the SV_COW_REFCNT_MAX of your Perl. (if COW is supported, this should be 255 unless customized). So if COW is around, expect 255 unless someone customized it. π
π«Ά AUTHOR π«Ά
shoutout to Nicolas R. <atoomic@cpan.org>. π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2018 by Nicolas R.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
mwah β source/version is perl v5.42.0, dated 2022-10-21, and this is the B::COW(3) manual. periodt. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-B-COW 0.007-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-B-COW 0.007-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-B-COW 0.007-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-B-COW 0.007-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms