Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-B-COW/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-B-COW/examples/synopsis.pl
#!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;

Hry