| 1 | # This code is part of Perl distribution OODoc version 3.05. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.05. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2003-2025 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package OODoc::Manifest;{ | ||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '3.05'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent 'OODoc::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Log::Report 'oodoc'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #-------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | use overload '@{}' => sub { [ shift->files ] }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | use overload bool => sub {1}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #-------------------- | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub init($) | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $self->SUPER::init($args) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $filename = $self->{OM_filename} = delete $args->{filename}; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | $self->{OM_files} = {}; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | $self->read if defined $filename && -e $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $filename and -e $filename
MC/DC0%0/2
defined $filename and -e $filename
defined $filename
-e $filename
Truth table0%0/3
A and B
A= defined $filenameB= -e $filename
| |||||||||||||||||||||||||||||
| 40 | 0 | $self->modified(0); | |||||||||||||||||||||||||||
| 41 | 0 | $self; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | #-------------------- | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub filename() { $_[0]->{OM_filename} } | ||||||||||||||||||||||||||
|
Subroutine
filename: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | #-------------------- | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub files() { keys %{ $_[0]->{OM_files}} } | ||||||||||||||||||||||||||
|
Subroutine
files: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub add(@) | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | while(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | { my $add = $self->relative(shift); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | $self->modified(1) unless exists $self->{O_file}{$add}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $self->{OM_files}{$add}++; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | $self; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #-------------------- | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub read() | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | open my $file, "<:encoding(utf8)", $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | or fault __x"cannot read manifest file {file}", file => $filename; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my @dist = $file->getlines; | |||||||||||||||||||||||||||
| 73 | 0 | $file->close; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | s/\s+.*\n?$// for @dist; | |||||||||||||||||||||||||||
| 76 | 0 | $self->{OM_files}{$_}++ foreach @dist; | |||||||||||||||||||||||||||
| 77 | 0 | $self; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub modified(;$) | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
modified: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | @_ ? $self->{OM_modified} = @_ : $self->{OM_modified}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub write() | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return unless $self->modified; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $filename = $self->filename || return $self; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->filename || (return $self)
MC/DC0%0/1
$self->filename || (return $self)
$self->filename
Truth table0%0/2
A
A= $self->filename
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | open my $file, ">:encoding(utf8)", $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | or fault __x"cannot write manifest {file}", file => $filename; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | $file->print($_, "\n") foreach sort $self->files; | |||||||||||||||||||||||||||
| 96 | 0 | $file->close; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | $self->modified(0); | |||||||||||||||||||||||||||
| 99 | 0 | $self; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub DESTROY() { $_[0]->write } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub relative($) | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | { my ($self, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
relative: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my $dir = dirname $self->filename; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | return $filename if $dir eq '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # normalize path for windows | ||||||||||||||||||||||||||||
| 112 | 0 | s!\\!/!g for $filename, $dir; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if(substr($filename, 0, length($dir)+1) eq "$dir/") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | { substr $filename, 0, length($dir)+1, ''; | |||||||||||||||||||||||||||
| 116 | 0 | return $filename; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | warning __x"MANIFEST file {file} lists filename outside (sub)directory: {out}", file => $self->filename, out => $filename; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $filename; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | 1; | |||||||||||||||||||||||||||