CatalystX-CMS
view release on metacpan or search on metacpan
lib/CatalystX/CMS/File.pm view on Meta::CPAN
print {$fh} join( "\n", $self->_ttify_attrs, $content )
or croak "write failed for $self: $!";
$fh->close;
return -s $self;
}
my $COMMENT = 'CXCMS COMMENT: DO NOT REMOVE';
my @special_tags = qw( textarea );
sub _escape {
my ( $self, $buf_ref ) = @_;
for my $tag (@special_tags) {
if ( $$buf_ref =~ m!</?$tag!i ) {
$$buf_ref =~ s,<(/?${tag}.*?)>,<!-- $COMMENT $1 -->,sgi;
}
}
}
sub _unescape {
my ( $self, $buf_ref ) = @_;
if ( $$buf_ref =~ m!$COMMENT!i ) {
$$buf_ref =~ s,<!-- $COMMENT (.+?) -->,<$1>,sgi;
}
}
=head2 create( I<user> )
Acquires lock for I<user> and writes files as a new page.
=cut
sub create {
my $self = shift;
my $user = shift or croak "user required";
# create any required parent directories
$self->dir->mkpath();
if ( $self->locked or -s $self ) {
croak "cannot create $self : locked or already exists";
}
$self->lock($user);
$self->attrs->{owner} = $user;
$self->content('[ this is a new page ]');
return $self->write(1);
}
=head2 update
Calls write().
B<NOTE:> This is not the same as the SVN::Class->update method!
If you want that method, use the up() alias instead.
=cut
sub update {
my $self = shift;
if ( !-s $self ) {
croak "cannot update an empty file";
}
$self->write(@_);
}
sub _ttify_attrs {
my $self = shift;
# make a TT-hash out of a Perl hash
my $attrs = $self->attrs;
my $buf = "[% # CMS\n\n";
for my $key ( sort keys %$attrs ) {
$buf .= " cmspage.attrs.$key = '" . qq($attrs->{$key}) . "';\n";
}
return $buf . "\n%]";
}
=head2 save( I<message> [, I<leave_lock>, I<username> ] )
Will write() file, add() to the SVN workspace if necessary,
and then call commit( I<message> ).
Returns -1 if status() of file indicates no modification.
Otherwise, returns commit() return value.
Pass a true for I<leave_lock> to leave the lock file intact
after the commit().
Pass an authorized I<username> to have the commit() made with that
credential.
=cut
sub save {
my $self = shift;
my $message = shift || '[no log message]';
my $leave_lock = shift || 0;
my $username = shift;
# pass force flag to write() since we want lock
# to persist till we've committed.
$self->write(1) or croak "$self failed to write(): $!";
# might be that the parent dir hasn't been added yet
# so will get err rather than status.
# track what level we need to commit at.
my @to_add;
my $dir = $self->dir;
$dir->debug( $self->debug );
my $self_status = $self->status;
my $dir_status = $dir->status;
if ( $self->debug ) {
warn "self = $self status = $self_status";
warn "dir = $dir status = $dir_status";
( run in 0.957 second using v1.01-cache-2.11-cpan-39bf76dae61 )