| 1 | # | ||||||||||||||||||
| 2 | # Copyright (c) 2003,2004,2005 Alexander Taler (dissent@0--0.org) | ||||||||||||||||||
| 3 | # | ||||||||||||||||||
| 4 | # All rights reserved. This program is free software; you can redistribute it | ||||||||||||||||||
| 5 | # and/or modify it under the same terms as Perl itself. | ||||||||||||||||||
| 6 | # | ||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | package VCS::LibCVS::Datum::FileMode; | ||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | VCS::LibCVS::Datum::FileMode - A CVS datum for the mode of a file | ||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | $string = VCS::LibCVS::Datum::FileMode->new("u=rw,g=rw,o=r"); | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | The mode of a file, simple UNIX-style file permissions, like "u=rw,g=rw,o=r". | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | =head1 SUPERCLASS | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | VCS::LibCVS::Datum | ||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | =cut | ||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | ############################################################################### | ||||||||||||||||||
| 32 | # Class constants | ||||||||||||||||||
| 33 | ############################################################################### | ||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Datum/FileMode.pm,v 1.10 2005/10/10 12:52:12 dissent Exp $ '; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | 1 | ▶ | use vars ('@ISA'); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 38 | 1 | @ISA = ("VCS::LibCVS::Datum"); | |||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | ############################################################################### | ||||||||||||||||||
| 41 | # Class variables | ||||||||||||||||||
| 42 | ############################################################################### | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | ############################################################################### | ||||||||||||||||||
| 45 | # Private variables | ||||||||||||||||||
| 46 | ############################################################################### | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | ############################################################################### | ||||||||||||||||||
| 49 | # Class routines | ||||||||||||||||||
| 50 | ############################################################################### | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | 0 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 53 | 0 | my $class = shift; | |||||||||||||||||
| 54 | 0 | my $that = $class->SUPER::new(@_); | |||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | 0 | ▶ | if ($that->{Mode} !~ /^([ugo]+=[rwx]*)(,[ugo]+=[rwx]*)+$/) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 57 | 0 | ▶ | if (-e $that->{Mode}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 58 | 0 | $that->_from_filename(); | |||||||||||||||||
| 59 | } else { | ||||||||||||||||||
| 60 | 0 | confess "Bad mode: $that->{Mode}" | |||||||||||||||||
| 61 | } | ||||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | 0 | return $that; | |||||||||||||||||
| 65 | } | ||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | ############################################################################### | ||||||||||||||||||
| 68 | # Instance routines | ||||||||||||||||||
| 69 | ############################################################################### | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | ############################################################################### | ||||||||||||||||||
| 72 | # Private routines | ||||||||||||||||||
| 73 | ############################################################################### | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | 0 | ▶ | sub _data_names { return ("Mode"); } | ||||||||||||||||
|
Subroutine
_data_names: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | # Get the mode of the file from its name | ||||||||||||||||||
| 78 | 0 | ▶ | sub _from_filename { | ||||||||||||||||
|
Subroutine
_from_filename: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||
| 80 | 0 | my $num = (stat($self->{Mode}))[2] & 0777; | |||||||||||||||||
| 81 | 0 | my $sym = "u=" . _n2s_digit($num >> 6) . ","; | |||||||||||||||||
| 82 | 0 | $sym .= "g=" . _n2s_digit($num >> 3) . ","; | |||||||||||||||||
| 83 | 0 | $sym .= "o=" . _n2s_digit($num); | |||||||||||||||||
| 84 | 0 | $self->{Mode} = $sym; | |||||||||||||||||
| 85 | } | ||||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | # Convert a single digit from numerical to symbolic | ||||||||||||||||||
| 88 | 0 | ▶ | sub _n2s_digit { | ||||||||||||||||
|
Subroutine
_n2s_digit: not called CC=4 SCAR=30.0
| |||||||||||||||||||
| 89 | 0 | my $n = shift; | |||||||||||||||||
| 90 | 0 | ▶ | return (($n & 04)?"r":"") . (($n & 02)?"w":"") . (($n & 01)?"x":""); | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 91 | } | ||||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | =head1 SEE ALSO | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | VCS::LibCVS::Datum | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | =cut | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | 1 | 1; | |||||||||||||||||