| 1 | package CatalystX::CMS::File; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | SVN::Class::File | ||||||||||||||||||||||||||||||||||||||||||
| 6 | Path::Class::File::Lockable | ||||||||||||||||||||||||||||||||||||||||||
| 7 | Class::Accessor::Fast | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '0.011'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | __PACKAGE__->mk_accessors(qw( attrs content ext has_unsaved_changes )); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | CatalystX::CMS::File - template file class | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | use CatalystX::CMS::File; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # longhand | ||||||||||||||||||||||||||||||||||||||||||
| 27 | my $file = CatalystX::CMS::File->new( $path_to_file ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | $file->fetch if $page->size; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | $file->content('hello world'); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | $file->title('super foo'); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | $file->write; | ||||||||||||||||||||||||||||||||||||||||||
| 32 | $file->commit or die $file->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # shorthand | ||||||||||||||||||||||||||||||||||||||||||
| 35 | my $file = CatalystX::CMS::File->new( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | path => $path_to_file, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | title => 'super foo', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | content => 'hello world', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | eval { $file->save } or die $file->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | print "$file was saved\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | CatalystX::CMS::File is the object model for the Template Toolkit files that | ||||||||||||||||||||||||||||||||||||||||||
| 46 | make up the content system of your application. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | Each object represents a C<.tt> | ||||||||||||||||||||||||||||||||||||||||||
| 48 | file on the filesystem in a Subversion working directory. | ||||||||||||||||||||||||||||||||||||||||||
| 49 | An object can be read, written, locked and unlocked on the filesystem. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | As a subclass of SVN::Class::File, the object can be interrogated | ||||||||||||||||||||||||||||||||||||||||||
| 51 | for its history, added, deleted, committed or updated. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | =head2 new( I<path> ) | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =head2 new( path => I<path> [, %param ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | Create a new object. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | Either form of new() may be used, but I<path> is always | ||||||||||||||||||||||||||||||||||||||||||
| 60 | required. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 23 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 23 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 23 | my @param = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 23 | my ( $self, %arg ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 23 | ▶ | if ( !@param ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | croak "path required"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | elsif ( @param == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | $self = $class->next::method(@param); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | elsif ( @param % 2 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | croak "new() requires either a path or a hash of key/value pairs"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ▶ | elsif ( @param == 2 && $param[0] ne 'path' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
@param == 2 and $param[0] ne "path"
MC/DC50%1/2
@param == 2 and $param[0] ne "path"
@param == 2
$param[0] ne "path"
Truth table66%2/3
A and B
A= @param == 2B= $param[0] ne "path"
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | $self = $class->next::method(@param); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | %arg = @param; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | ▶ | my $path = delete $arg{path} or croak "path required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | $self = $class->next::method($path); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # add other attributes | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | $self->{$_} = $arg{$_} for keys %arg; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 23 | ▶ | $self->{attrs} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"attrs"} ||= {}
MC/DC0%0/1
$self->{"attrs"} ||= {}
$self->{"attrs"}
Truth table50%1/2
A
A= $self->{"attrs"}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # path cleanup | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 23 | ▶ | $self->{ext} ||= '.tt'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"ext"} ||= ".tt"
MC/DC0%0/1
$self->{"ext"} ||= ".tt"
$self->{"ext"}
Truth table50%1/2
A
A= $self->{"ext"}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # re-create the object with extension | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 23 | my $ext = $self->{ext}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 23 | ▶ | unless ( $self =~ m/$ext$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | $self = $self->new( $self . $self->{ext} ); | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | #carp dump $self; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =head2 read | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | Reads the file from disk and parses the metadata attributes and content, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | thereafter accessible via the attrs() and content() methods. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | Will croak if path() is false, empty or non-existent. | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=6 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | croak("invalid path: $self") unless ( -f $self && -s $self ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $self and -s $self
MC/DC0%0/2
-f $self and -s $self
-f $self
-s $self
Truth table33%1/3
A and B
A= -f $selfB= -s $self
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # TODO does ->slurp correctly handle utf8? | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | $self->_parse_page( scalar $self->slurp ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | #$self->debug(1); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # cache whether we have local mods | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | my $committed = $self->committed; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $diff = $self->diff; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | chomp( my $outstr = $self->outstr ); | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | #warn "committed = $committed\ndiff = $diff\noutstr = $outstr\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | ▶ | if ( $committed && $diff && length $outstr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$committed and $diff and length $outstr
$committed and $diff
MC/DC0%0/3
$committed and $diff and length $outstr
$committed
$diff
length $outstr
Truth table25%1/4
A and B and C
A= $committedB= $diffC= length $outstr
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->has_unsaved_changes(1); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | #$self->debug(0); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =head2 committed | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | Returns true if the delegate file has ever been committed to the repository. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | ▶ | sub committed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
committed: called CC=6 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | my $stat = $self->status; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | #warn "status = $stat"; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | #warn "error = " . $self->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ( $stat == 0 && grep {m/is not a working copy/} @{ $self->stderr } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$stat == 0 and grep {/is not a working copy/;} @{$self->stderr;}
MC/DC0%0/2
$stat == 0 and grep {/is not a working copy/;} @{$self->stderr;}
$stat == 0
grep {/is not a working copy/;} @{$self->stderr;}
Truth table33%1/3
A and B
A= $stat == 0B= grep {/is not a working copy/;} @{$self->stderr;}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | #warn "committed == 0"; | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | elsif ($stat) { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | # some status means svn knows about it or its parent dir. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ▶ | elsif ( $stat == 0 | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$stat == 0 and not $self->error
MC/DC0%0/2
$stat == 0 and not $self->error
$stat == 0
not $self->error
Truth table33%1/3
A and not(B)
A= $stat == 0B= not $self->error
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | && !$self->error ) | ||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | ▶ | sub _parse_page { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_page: called CC=8 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | my ( $self, $buf ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # example: | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # [% # CMS | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # cmspage.attrs.title = 'foo' | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # %] | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # this is a page. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | $self->_escape( \$buf ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | my ( $attrs, $content ) | |||||||||||||||||||||||||||||||||||||||||
| 187 | = ( $buf =~ m/^\s*\[\%\s+\#\s*CMS\s+(.+?)\%\]\s*(.*)$/s ); | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | ▶ | if ( $attrs && $content ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$attrs and $content
MC/DC0%0/2
$attrs and $content
$attrs
$content
Truth table33%1/3
A and B
A= $attrsB= $content
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | my $depth = 100; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | ▶ | while ( $attrs =~ m/\bcmspage\.attrs\.(\w+)\s*=\s*(['"])(.+?)\2/sg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | ▶ | last if $count++ > $depth; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | my $key = $1; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 4 | my $val = $3; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # reserved words | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | next if $key eq 'attrs'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | next if $key eq 'content'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | ▶ | next if $key eq 'page'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | $self->{attrs}->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | $self->content($content); | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $self->content($buf); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | =head2 write( [I<ignore_lock>] ) | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | Writes attrs() and content() to file location in TT-compatible format. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | Will croak on any error. | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | If the I<ignore_lock> flag is true, write() will ignore any true | ||||||||||||||||||||||||||||||||||||||||||
| 221 | value of locked(). Otherwise, will croak() if locked() is true. | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | Returns the size of the resulting file. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | my $force = shift || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | if ( $self->locked && !$force ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->locked and not $force
MC/DC0%0/2
$self->locked and not $force
$self->locked
not $force
Truth table33%1/3
A and not(B)
A= $self->lockedB= not $force
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | croak "write failed. $self is locked"; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | my $fh = $self->openw(); | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | # make sure we have at least one newline at end of file. | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | ▶ | my $content = $self->content || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->content || ''
MC/DC0%0/1
$self->content || ''
$self->content
Truth table50%1/2
A
A= $self->content
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | chomp $content; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | $content .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | $self->_unescape( \$content ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | print {$fh} join( "\n", $self->_ttify_attrs, $content ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | or croak "write failed for $self: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | return -s $self; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | my $COMMENT = 'CXCMS COMMENT: DO NOT REMOVE'; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | my @special_tags = qw( textarea ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | ▶ | sub _escape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | my ( $self, $buf_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | for my $tag (@special_tags) { | |||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | ▶ | if ( $$buf_ref =~ m!</?$tag!i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $$buf_ref =~ s,<(/?${tag}.*?)>,<!-- $COMMENT $1 -->,sgi; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ▶ | sub _unescape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unescape: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | my ( $self, $buf_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | ▶ | if ( $$buf_ref =~ m!$COMMENT!i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $$buf_ref =~ s,<!-- $COMMENT (.+?) -->,<$1>,sgi; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | =head2 create( I<user> ) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | Acquires lock for I<user> and writes files as a new page. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | my $user = shift or croak "user required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # create any required parent directories | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | $self->dir->mkpath(); | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | if ( $self->locked or -s $self ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->locked or -s $self
MC/DC0%0/2
$self->locked or -s $self
$self->locked
-s $self
Truth table33%1/3
A or B
A= $self->lockedB= -s $self
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | croak "cannot create $self : locked or already exists"; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $self->lock($user); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | $self->attrs->{owner} = $user; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | $self->content('[ this is a new page ]'); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | return $self->write(1); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | =head2 update | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | Calls write(). | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | B<NOTE:> This is not the same as the SVN::Class->update method! | ||||||||||||||||||||||||||||||||||||||||||
| 299 | If you want that method, use the up() alias instead. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ( !-s $self ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | croak "cannot update an empty file"; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->write(@_); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | sub _ttify_attrs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ttify_attrs: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # make a TT-hash out of a Perl hash | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | my $attrs = $self->attrs; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | my $buf = "[% # CMS\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | for my $key ( sort keys %$attrs ) { | |||||||||||||||||||||||||||||||||||||||||
| 318 | 3 | $buf .= " cmspage.attrs.$key = '" . qq($attrs->{$key}) . "';\n"; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | return $buf . "\n%]"; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | =head2 save( I<message> [, I<leave_lock>, I<username> ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | Will write() file, add() to the SVN workspace if necessary, | ||||||||||||||||||||||||||||||||||||||||||
| 326 | and then call commit( I<message> ). | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | Returns -1 if status() of file indicates no modification. | ||||||||||||||||||||||||||||||||||||||||||
| 329 | Otherwise, returns commit() return value. | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | Pass a true for I<leave_lock> to leave the lock file intact | ||||||||||||||||||||||||||||||||||||||||||
| 332 | after the commit(). | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | Pass an authorized I<username> to have the commit() made with that | ||||||||||||||||||||||||||||||||||||||||||
| 335 | credential. | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=23 SCAR=47.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | ▶ | my $message = shift || '[no log message]'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || '[no log message]'
MC/DC0%0/1
shift() || '[no log message]'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | ▶ | my $leave_lock = shift || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | my $username = shift; | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | # pass force flag to write() since we want lock | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # to persist till we've committed. | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | ▶ | $self->write(1) or croak "$self failed to write(): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # might be that the parent dir hasn't been added yet | ||||||||||||||||||||||||||||||||||||||||||
| 351 | # so will get err rather than status. | ||||||||||||||||||||||||||||||||||||||||||
| 352 | # track what level we need to commit at. | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | my @to_add; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | my $dir = $self->dir; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | $dir->debug( $self->debug ); | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | my $self_status = $self->status; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | my $dir_status = $dir->status; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | if ( $self->debug ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | warn "self = $self status = $self_status"; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | warn "dir = $dir status = $dir_status"; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | # walk up the tree | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | ▶ | while ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$dir_status eq 0 and $dir->errstr || grep({/is not a working copy/;} @{$dir->stderr;})
$dir->errstr or grep {/is not a working copy/;} @{$dir->stderr;}
MC/DC0%0/3
$dir_status eq 0 and $dir->errstr || grep({/is not a working copy/;} @{$dir->stderr;})
$dir_status eq 0
$dir->errstr
grep {/is not a working copy/;} @{$dir->stderr;}
Truth table25%1/4
A and B or C
A= $dir_status eq 0B= $dir->errstrC= grep {/is not a working copy/;} @{$dir->stderr;}
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | $dir_status eq '0' | ||||||||||||||||||||||||||||||||||||||||||
| 369 | && ( $dir->errstr | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | || grep {/is not a working copy/} @{ $dir->stderr } ) | |||||||||||||||||||||||||||||||||||||||||
| 371 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | $self->debug and warn "no status for $dir"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | unshift( @to_add, $dir ); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $dir = $dir->parent; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $dir_status = $dir->status; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | $self->debug and warn "dir $dir status = $dir_status"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | # avoid infinite loops | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( $dir eq '/' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | croak "infinite loop looking up svn workdir tree for $self"; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | # found one that svn knows about | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | if ( $dir_status eq '?' or $dir_status eq 'A' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dir_status eq "?" or $dir_status eq "A"
MC/DC0%0/2
$dir_status eq "?" or $dir_status eq "A"
$dir_status eq "?"
$dir_status eq "A"
Truth table33%1/3
A or B
A= $dir_status eq "?"B= $dir_status eq "A"
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | unshift( @to_add, $dir ); | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | ▶ | $self->debug and warn "to_add: " . dump \@to_add; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | # we 'add' each dir non-recursively | ||||||||||||||||||||||||||||||||||||||||||
| 394 | # so that we do not add unaffected files (like lock files) by mistake. | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | for my $d (@to_add) { | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | $d->add( ['-N'] ) unless $d->status eq 'A'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my @opts = '-N'; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if ($username) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | push( @opts, "--username $username" ); | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | $d->commit( "new directory", \@opts ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | or croak "add directory $d failed: " . $d->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | # now check the stat of the file itself | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | my $stat = $self->status; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | if ( $stat && $stat eq '?' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$stat and $stat eq "?"
MC/DC0%0/2
$stat and $stat eq "?"
$stat
$stat eq "?"
Truth table33%1/3
A and B
A= $statB= $stat eq "?"
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $self->add; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | # is file modified at all? | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | if ( $self->modified ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $ret = $self->commit($message); | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | # no attempt made to commit unmodified file | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | $ret = -1; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | ▶ | unless ($leave_lock) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | ▶ | $self->unlock or croak "can't unlock $self: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | =head2 escape_tt | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | Returns content() with all TT code wrapped in special XHTML tagset | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | <code class="tt"> | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | This is to allow for such code to be escaped online or otherwise parsed | ||||||||||||||||||||||||||||||||||||||||||
| 436 | with a XML parser. | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | sub escape_tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escape_tt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $content = $self->content; | |||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $content =~ s/\[\%/<code class="tt">\[\%/g; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $content =~ s/\%\]/\%\]<\/code>/g; | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | # this isn't currently used but could be. | ||||||||||||||||||||||||||||||||||||||||||
| 451 | #sub as_chunks { | ||||||||||||||||||||||||||||||||||||||||||
| 452 | # my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # my $escape = shift || 0; | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # | ||||||||||||||||||||||||||||||||||||||||||
| 455 | # # NOTE the regex keeps the surrounding whitespace WITH the PROCESS | ||||||||||||||||||||||||||||||||||||||||||
| 456 | # # line so that it is preserved in the web interaction. | ||||||||||||||||||||||||||||||||||||||||||
| 457 | # my @chunks = split( m!(\s*\[\%\ +PROCESS tt/share/\S+\ +\%\]\s*)!s, | ||||||||||||||||||||||||||||||||||||||||||
| 458 | # $self->content ); | ||||||||||||||||||||||||||||||||||||||||||
| 459 | # | ||||||||||||||||||||||||||||||||||||||||||
| 460 | # # turn into array of hashrefs | ||||||||||||||||||||||||||||||||||||||||||
| 461 | # my @hashes; | ||||||||||||||||||||||||||||||||||||||||||
| 462 | # | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # #carp "raw chunks: " . dump \@chunks; | ||||||||||||||||||||||||||||||||||||||||||
| 464 | # | ||||||||||||||||||||||||||||||||||||||||||
| 465 | # for my $chunk (@chunks) { | ||||||||||||||||||||||||||||||||||||||||||
| 466 | # my $h = { content => $chunk }; | ||||||||||||||||||||||||||||||||||||||||||
| 467 | # | ||||||||||||||||||||||||||||||||||||||||||
| 468 | # # editable text | ||||||||||||||||||||||||||||||||||||||||||
| 469 | # unless ( $chunk =~ m/^\s*\[\%\s+PROCESS/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 470 | # $h->{editable} = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 471 | # | ||||||||||||||||||||||||||||||||||||||||||
| 472 | # # wrap TT instructions in <pre> tags so they show verbatim | ||||||||||||||||||||||||||||||||||||||||||
| 473 | # if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||
| 474 | # $h->{content} =~ s,\[\%,<pre class="tt">\[\%,g; | ||||||||||||||||||||||||||||||||||||||||||
| 475 | # $h->{content} =~ s,\%\],\%\]</pre>,g; | ||||||||||||||||||||||||||||||||||||||||||
| 476 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | # | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # # shared text -- render it as TT would but just that chunk. | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # else { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # $h->{editable} = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 483 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | # | ||||||||||||||||||||||||||||||||||||||||||
| 485 | # push( @hashes, $h ); | ||||||||||||||||||||||||||||||||||||||||||
| 486 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | # | ||||||||||||||||||||||||||||||||||||||||||
| 488 | # return \@hashes; | ||||||||||||||||||||||||||||||||||||||||||
| 489 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 490 | # | ||||||||||||||||||||||||||||||||||||||||||
| 491 | #=head2 save_chunk( I<chunk_id>, I<new_text>, I<message> ) | ||||||||||||||||||||||||||||||||||||||||||
| 492 | # | ||||||||||||||||||||||||||||||||||||||||||
| 493 | #I<chunk_id> is element of the array returned by as_chunks(). | ||||||||||||||||||||||||||||||||||||||||||
| 494 | # | ||||||||||||||||||||||||||||||||||||||||||
| 495 | #I<new_text> is the text to be saved at that element. | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # | ||||||||||||||||||||||||||||||||||||||||||
| 497 | #Calls save() with I<message>. Returns save() return value. | ||||||||||||||||||||||||||||||||||||||||||
| 498 | # | ||||||||||||||||||||||||||||||||||||||||||
| 499 | #=cut | ||||||||||||||||||||||||||||||||||||||||||
| 500 | # | ||||||||||||||||||||||||||||||||||||||||||
| 501 | #sub save_chunk { | ||||||||||||||||||||||||||||||||||||||||||
| 502 | # my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 503 | # my $id = shift || 0; | ||||||||||||||||||||||||||||||||||||||||||
| 504 | # my $text = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | # my $message = shift or croak "need save message"; | ||||||||||||||||||||||||||||||||||||||||||
| 506 | # | ||||||||||||||||||||||||||||||||||||||||||
| 507 | # my $chunks = $self->as_chunks; # NO escape | ||||||||||||||||||||||||||||||||||||||||||
| 508 | # | ||||||||||||||||||||||||||||||||||||||||||
| 509 | # $chunks->[$id]->{content} = $text; | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # | ||||||||||||||||||||||||||||||||||||||||||
| 511 | # carp dump $chunks; | ||||||||||||||||||||||||||||||||||||||||||
| 512 | # | ||||||||||||||||||||||||||||||||||||||||||
| 513 | # $self->content( join( '', map { $_->{content} } @$chunks ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # return $self->save( $message, 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 516 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | __END__ | ||||||||||||||||||||||||||||||||||||||||||