| 1 | package CatalystX::CMS::Page; | ||||||||||||||||||||
| 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( CatalystX::CRUD::Object ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use CatalystX::CMS::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use MRO::Compat; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use mro 'c3'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use overload( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 24 | ▶ | q[""] => sub { shift->delegate }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | fallback => 1, | |||||||||||||||||||
| 14 | 2 | ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | our $VERSION = '0.011'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | __PACKAGE__->mk_accessors(qw( cms_root file copy url has_unsaved_changes )); | |||||||||||||||||||
| 19 | 2 | __PACKAGE__->delegate_class('CatalystX::CMS::File'); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 NAME | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | CatalystX::CMS::Page - content storage class | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | my $page = $c->model('CMS')->fetch(file => 'foo/bar'); | ||||||||||||||||||||
| 28 | # $page isa CatalystX::CMS::Page | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | CatalystX::CMS::Page is a subclass of CatalystX::CRUD::Object. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 METHODS | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Only new or overridden method are documented here. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head2 new( file => I<path/to/file> ) | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | Returns new CatalystX::CMS::Page object. | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 5 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||
| 47 | 5 | my $class = shift; | |||||||||||||||||||
| 48 | 5 | my $self = $class->next::method(@_); | |||||||||||||||||||
| 49 | 5 | ▶ | my $file = $self->{file} or $self->throw_error("file param required"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 5 | ▶ | $self->{delegate} ||= $self->delegate_class->new( path => $file ); | ||||||||||||||||||
|
Condition33%1/3
$self->{"delegate"} ||= $self->delegate_class->new("path", $file)
MC/DC0%0/2
$self->{"delegate"} ||= $self->delegate_class->new("path", $file)
$self->{"delegate"}
$self->delegate_class->new("path", $file)
Truth table33%1/3
A ||= B
A= $self->{"delegate"}B= $self->delegate_class->new("path", $file)
| |||||||||||||||||||||
| 51 | 5 | return $self; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head2 create | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | Calls create() on the delegate(), passing all params. | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 1 | ▶ | sub create { shift->{delegate}->create(@_) } | ||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head2 read | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | Calls read() on the delegate(), passing all params. | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 3 | ▶ | sub read { shift->{delegate}->read(@_) } | ||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head2 update | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | Calls update() on the delegate(), passing all params. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | ▶ | sub update { shift->{delegate}->update(@_) } | ||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =head2 delete | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Calls delete() on the delegate(), passing all params. | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | sub delete { shift->{delegate}->delete(@_) } | ||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head2 url | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | Returns file() stringified. | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head2 calc_url | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Determines the url value based on file(), type() | ||||||||||||||||||||
| 95 | and flavour(). Sets the url() value and returns the value. | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | sub calc_url { | ||||||||||||||||||
|
Subroutine
calc_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||
| 101 | 0 | my $file = $self->file; | |||||||||||||||||||
| 102 | 0 | my $type = $self->type; | |||||||||||||||||||
| 103 | 0 | my $flav = $self->flavour; | |||||||||||||||||||
| 104 | 0 | my $ext = $self->delegate->ext; | |||||||||||||||||||
| 105 | 0 | $file =~ s!^$type[\/\\]!!; | |||||||||||||||||||
| 106 | 0 | $file =~ s!^$flav[\/\\]!!; | |||||||||||||||||||
| 107 | 0 | $file =~ s!\Q$ext\E$!!; | |||||||||||||||||||
| 108 | 0 | $self->url($file); | |||||||||||||||||||
| 109 | 0 | return $file; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =head2 title | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | Returns the C<title> from attrs(). | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 3 | ▶ | sub title { | ||||||||||||||||||
|
Subroutine
title: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 119 | 3 | shift->attrs->{title}; | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head2 type | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | Returns the C<type> from attrs() or the local type if overriden in the I<page>. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 10 | ▶ | sub type { | ||||||||||||||||||
|
Subroutine
type: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 129 | 10 | ▶ | $_[0]->attrs->{type} || $_[0]->{type}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =head2 flavour | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | Returns the C<flavour> from attrs() or the local flavour if overriden in the I<page>. | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 9 | ▶ | sub flavour { | ||||||||||||||||||
|
Subroutine
flavour: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 139 | 9 | ▶ | $_[0]->attrs->{flavour} || $_[0]->{flavour}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | ▶ | sub _parent_dir { | ||||||||||||||||||
|
Subroutine
_parent_dir: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 143 | 0 | my $self = shift; | |||||||||||||||||||
| 144 | 0 | ▶ | my $file = shift or croak 'file required'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 145 | 0 | my $dir = $file->parent; | |||||||||||||||||||
| 146 | 0 | return $dir->relative( $dir->parent ); | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =head2 bare_file | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | Returns the delegate basename() without any file extension (as indicated | ||||||||||||||||||||
| 152 | by the delegate ext() value). | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | ▶ | sub bare_file { | ||||||||||||||||||
|
Subroutine
bare_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||
| 158 | 0 | my $file = $self->delegate->file->basename; | |||||||||||||||||||
| 159 | 0 | my $ext = $self->delegate->ext; | |||||||||||||||||||
| 160 | 0 | $file =~ s/\Q$ext\E$//; | |||||||||||||||||||
| 161 | 0 | return $file; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =head2 tree | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | Returns array suitable for templating. The array data | ||||||||||||||||||||
| 167 | are the related URLs for the wrapper set for this Page. | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 1 | ▶ | sub tree { | ||||||||||||||||||
|
Subroutine
tree: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||
| 172 | 1 | my $self = shift; | |||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | #carp dump $self; | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 1 | my $file = $self->delegate; | |||||||||||||||||||
| 177 | 1 | my $class = $self->delegate_class; | |||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | # for any given page, we can't easily discover | ||||||||||||||||||||
| 180 | # which other pages might be INCLUDEing it, | ||||||||||||||||||||
| 181 | # so don't even try. Maybe make that a different | ||||||||||||||||||||
| 182 | # feature. | ||||||||||||||||||||
| 183 | # instead, just include the wrappers/* files | ||||||||||||||||||||
| 184 | # along with the current $file and its immediate | ||||||||||||||||||||
| 185 | # descendents. | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 1 | my @tree; | |||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 1 | for my $t (qw( wrapper header footer body )) { | |||||||||||||||||||
| 190 | 4 | ▶ | next if $self->url eq $t; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 191 | 4 | my %item = ( | |||||||||||||||||||
| 192 | url => $t, | ||||||||||||||||||||
| 193 | text => $t, | ||||||||||||||||||||
| 194 | type => $self->type, | ||||||||||||||||||||
| 195 | flavour => $self->flavour, | ||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||
| 197 | 4 | push( @tree, \%item ); | |||||||||||||||||||
| 198 | } | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | 1 | my $children = $self->_parse_tt_includes( $file->content ); | |||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | 1 | my @subtree; | |||||||||||||||||||
| 203 | 1 | for my $f (@$children) { | |||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | # TODO better way to get type and flavour | ||||||||||||||||||||
| 206 | # for $f. could be an attr in the file, | ||||||||||||||||||||
| 207 | # could be determined from path, etc. | ||||||||||||||||||||
| 208 | # for now, we just assume the parent's attrs | ||||||||||||||||||||
| 209 | 0 | my $type = $self->type; | |||||||||||||||||||
| 210 | 0 | my $flavour = $self->flavour; | |||||||||||||||||||
| 211 | 0 | my %item = ( | |||||||||||||||||||
| 212 | url => $f, | ||||||||||||||||||||
| 213 | text => $f, | ||||||||||||||||||||
| 214 | type => $type, | ||||||||||||||||||||
| 215 | flavour => $flavour, | ||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||
| 217 | 0 | push( @subtree, \%item ); | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | 1 | push( @tree, | |||||||||||||||||||
| 221 | { url => $self->url, text => $self->url, tree => \@subtree } ); | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | 1 | return \@tree; | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | 1 | ▶ | sub _parse_tt_includes { | ||||||||||||||||||
|
Subroutine
_parse_tt_includes: called CC=5 SCAR=23.6
| |||||||||||||||||||||
| 227 | 1 | my $self = shift; | |||||||||||||||||||
| 228 | 1 | my $buf = shift; | |||||||||||||||||||
| 229 | 1 | my $ext = $self->ext; | |||||||||||||||||||
| 230 | 1 | my @files; | |||||||||||||||||||
| 231 | 1 | my $depth = 100; | |||||||||||||||||||
| 232 | 1 | my $count = 0; | |||||||||||||||||||
| 233 | 1 | ▶ | while ( $buf =~ m/(PROCESS|INCLUDE|INSERT) (\S+)/g ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 234 | 0 | ▶ | last if $count++ > $depth; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 235 | 0 | my $f = $2; | |||||||||||||||||||
| 236 | 0 | ▶ | unless ( $buf =~ m/BLOCK\ +$f/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 237 | 0 | $f =~ s/$ext$//; | |||||||||||||||||||
| 238 | 0 | $f =~ s/\s*;$//; | |||||||||||||||||||
| 239 | 0 | ▶ | next if $f =~ m/[\$'"]/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 240 | 0 | push( @files, $f ); | |||||||||||||||||||
| 241 | } | ||||||||||||||||||||
| 242 | } | ||||||||||||||||||||
| 243 | 1 | return \@files; | |||||||||||||||||||
| 244 | } | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | 2 | 1; | |||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | __END__ | ||||||||||||||||||||