| 1 | package Grimlock::Schema::Result::Entry; | ||||||||||
| 2 | { | ||||||||||
| 3 | 6 | $Grimlock::Schema::Result::Entry::VERSION = '0.11'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | 6 | ▶ | use Grimlock::Schema::Candy -components => [ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | qw( | ||||||||||
| 8 | TimeStamp | ||||||||||
| 9 | Helper::Row::ToJSON | ||||||||||
| 10 | +DBICx::MaterializedPath | ||||||||||
| 11 | ) | ||||||||||
| 12 | 6 | ]; | |||||||||
| 13 | |||||||||||
| 14 | 6 | ▶ | use HTML::Scrubber; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 6 | resultset_class 'Grimlock::Schema::ResultSet::Entry'; | |||||||||
| 17 | |||||||||||
| 18 | 6 | primary_column entryid => { | |||||||||
| 19 | data_type => 'int', | ||||||||||
| 20 | is_nullable => 0, | ||||||||||
| 21 | is_auto_increment => 1, | ||||||||||
| 22 | extra => { unsigned => 1 }, | ||||||||||
| 23 | }; | ||||||||||
| 24 | |||||||||||
| 25 | 6 | unique_column title => { | |||||||||
| 26 | data_type => 'varchar', | ||||||||||
| 27 | size => 200, | ||||||||||
| 28 | is_nullable => 0, | ||||||||||
| 29 | }; | ||||||||||
| 30 | |||||||||||
| 31 | 6 | unique_column display_title => { | |||||||||
| 32 | data_type => 'varchar', | ||||||||||
| 33 | size => 200, | ||||||||||
| 34 | is_nullable => 0, | ||||||||||
| 35 | }; | ||||||||||
| 36 | |||||||||||
| 37 | 6 | column path => { | |||||||||
| 38 | data_type => 'varchar', | ||||||||||
| 39 | size => 255, | ||||||||||
| 40 | is_nullable => 1 | ||||||||||
| 41 | }; | ||||||||||
| 42 | |||||||||||
| 43 | 6 | column parent => { | |||||||||
| 44 | data_type => 'bigint', | ||||||||||
| 45 | is_nullable => 1, | ||||||||||
| 46 | extra => { unsigned => 1 }, | ||||||||||
| 47 | is_foreign_key => 1 | ||||||||||
| 48 | }; | ||||||||||
| 49 | |||||||||||
| 50 | 6 | column body => { | |||||||||
| 51 | data_type => 'text', | ||||||||||
| 52 | is_nullable => 0, | ||||||||||
| 53 | }; | ||||||||||
| 54 | |||||||||||
| 55 | 6 | column author => { | |||||||||
| 56 | data_type => 'int', | ||||||||||
| 57 | is_nullable => 0, | ||||||||||
| 58 | extra => { unsigned => 1 }, | ||||||||||
| 59 | }; | ||||||||||
| 60 | |||||||||||
| 61 | 6 | column created_at => { | |||||||||
| 62 | data_type => 'datetime', | ||||||||||
| 63 | is_nullable => 0, | ||||||||||
| 64 | set_on_create => 1, | ||||||||||
| 65 | accessor => '_created_at' | ||||||||||
| 66 | }; | ||||||||||
| 67 | |||||||||||
| 68 | 6 | column updated_at => { | |||||||||
| 69 | data_type => 'datetime', | ||||||||||
| 70 | is_nullable => 1, | ||||||||||
| 71 | set_on_create => 1, | ||||||||||
| 72 | set_on_update => 1 | ||||||||||
| 73 | }; | ||||||||||
| 74 | |||||||||||
| 75 | 6 | column published => { | |||||||||
| 76 | data_type => 'tinyint', | ||||||||||
| 77 | is_nullable => 0, | ||||||||||
| 78 | default_value => 0 | ||||||||||
| 79 | }; | ||||||||||
| 80 | |||||||||||
| 81 | 6 | belongs_to 'author' => 'Grimlock::Schema::Result::User', { | |||||||||
| 82 | 'foreign.userid' => 'self.author', | ||||||||||
| 83 | }; | ||||||||||
| 84 | |||||||||||
| 85 | 6 | belongs_to 'parent' => __PACKAGE__, { | |||||||||
| 86 | 'foreign.entryid' => 'self.parent', | ||||||||||
| 87 | }, | ||||||||||
| 88 | { | ||||||||||
| 89 | join_type => 'LEFT', | ||||||||||
| 90 | }; | ||||||||||
| 91 | |||||||||||
| 92 | 6 | has_many 'children' => __PACKAGE__, { | |||||||||
| 93 | 'foreign.parent' => 'self.entryid' | ||||||||||
| 94 | }; | ||||||||||
| 95 | |||||||||||
| 96 | 6 | __PACKAGE__->mk_classdata( path_column => "path" ); | |||||||||
| 97 | 6 | __PACKAGE__->mk_classdata( path_separator => "." ); | |||||||||
| 98 | |||||||||||
| 99 | 6 | ▶ | sub insert { | ||||||||
|
Subroutine
insert: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 100 | 6 | my ( $self, @args ) = @_; | |||||||||
| 101 | |||||||||||
| 102 | # move me to a filter class | ||||||||||
| 103 | 6 | my $guard = $self->result_source->schema->txn_scope_guard; | |||||||||
| 104 | |||||||||||
| 105 | 6 | $self->clean_params([qw( title body )]); | |||||||||
| 106 | |||||||||||
| 107 | # move me to a filter class | ||||||||||
| 108 | 6 | my $title = $self->title; | |||||||||
| 109 | 6 | $title =~ s{(\W+|\s+|\_)}{-}g; | |||||||||
| 110 | 6 | ▶ | chomp $title if $title =~ m/\W$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 6 | $self->display_title($title); | |||||||||
| 112 | 6 | $self->next::method(@args); | |||||||||
| 113 | |||||||||||
| 114 | 6 | $guard->commit; | |||||||||
| 115 | 6 | return $self; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | |||||||||||
| 119 | 6 | ▶ | sub scrubber { | ||||||||
|
Subroutine
scrubber: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 120 | 6 | my $self = shift; | |||||||||
| 121 | 6 | return HTML::Scrubber->new(allow => [ qw[ p b i u hr br ] ] ); | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 6 | ▶ | sub clean_params { | ||||||||
|
Subroutine
clean_params: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 125 | 6 | my ( $self, $params ) = @_; | |||||||||
| 126 | # need to add a filter to deal with this | ||||||||||
| 127 | 6 | my $scrubber = $self->scrubber; | |||||||||
| 128 | 6 | for my $column ( @{ $params } ) { | |||||||||
| 129 | 12 | warn "CLEANING $column"; | |||||||||
| 130 | 12 | my $scrubbed = $scrubber->scrub($self->$column); | |||||||||
| 131 | 12 | $self->$column($scrubbed); | |||||||||
| 132 | } | ||||||||||
| 133 | 6 | return $self | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | |||||||||||
| 137 | 5 | ▶ | sub sqlt_deploy_hook { | ||||||||
|
Subroutine
sqlt_deploy_hook: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 138 | 5 | my ($self, $sqlt_table) = @_; | |||||||||
| 139 | |||||||||||
| 140 | 5 | $sqlt_table->add_index(name => 'tree_data', fields => ['parent']); | |||||||||
| 141 | } | ||||||||||
| 142 | |||||||||||
| 143 | 6 | ▶ | sub reply_count { | ||||||||
|
Subroutine
reply_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 144 | 6 | my $self = shift; | |||||||||
| 145 | 6 | return $self->children->count; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 8 | ▶ | sub created_at { | ||||||||
|
Subroutine
created_at: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 149 | 8 | my $self = shift; | |||||||||
| 150 | 8 | my $created_at = $self->_created_at; | |||||||||
| 151 | 8 | my $date_time = $created_at->month_name . " " . | |||||||||
| 152 | $created_at->day . ", " . | ||||||||||
| 153 | $created_at->year . " at " . | ||||||||||
| 154 | $created_at->hms . " " . | ||||||||||
| 155 | $created_at->time_zone->name; | ||||||||||
| 156 | 8 | return $date_time; | |||||||||
| 157 | } | ||||||||||
| 158 | |||||||||||
| 159 | |||||||||||
| 160 | 0 | ▶ | sub TO_JSON { | ||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 161 | 0 | my $self = shift; | |||||||||
| 162 | return { | ||||||||||
| 163 | reply_count => $self->reply_count, | ||||||||||
| 164 | children => $self->children_TO_JSON, | ||||||||||
| 165 | parent => $self->parent, | ||||||||||
| 166 | body => $self->body, | ||||||||||
| 167 | 0 | %{ $self->next::method }, | |||||||||
| 168 | } | ||||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | 0 | ▶ | sub children_TO_JSON { | ||||||||
|
Subroutine
children_TO_JSON: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 172 | 0 | my $self = shift; | |||||||||
| 173 | 0 | my $children_rs = $self->children; | |||||||||
| 174 | 0 | my @child_collection; | |||||||||
| 175 | push @child_collection, { | ||||||||||
| 176 | entryid => $_->entryid, | ||||||||||
| 177 | title => $_->title, | ||||||||||
| 178 | display_title => $_->display_title, | ||||||||||
| 179 | path => $_->path, | ||||||||||
| 180 | parent => $_->parent, | ||||||||||
| 181 | body => $_->body, | ||||||||||
| 182 | author => $_->author, | ||||||||||
| 183 | created_at => $_->created_at . "", | ||||||||||
| 184 | updated_at => $_->updated_at . "", | ||||||||||
| 185 | published => $_->published, | ||||||||||
| 186 | reply_count => $_->reply_count, | ||||||||||
| 187 | children => $_->children_TO_JSON, | ||||||||||
| 188 | parent => $_->parent, | ||||||||||
| 189 | 0 | } for $children_rs->all; | |||||||||
| 190 | |||||||||||
| 191 | 0 | return \@child_collection; | |||||||||
| 192 | } | ||||||||||
| 193 | |||||||||||
| 194 | 6 | 1; | |||||||||