| 1 | package Grimlock::Schema::Result::User; | ||
| 2 | { | ||
| 3 | 6 | $Grimlock::Schema::Result::User::VERSION = '0.11'; | |
| 4 | } | ||
| 5 | |||
| 6 | 6 | ▶ | use Grimlock::Schema::Candy -components => [ |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | qw( | ||
| 8 | InflateColumn::DateTime | ||
| 9 | TimeStamp | ||
| 10 | Helper::Row::ToJSON | ||
| 11 | EncodedColumn | ||
| 12 | ) | ||
| 13 | 6 | ]; | |
| 14 | 6 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 6 | ▶ | use Text::Password::Pronounceable; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 6 | resultset_class 'Grimlock::Schema::ResultSet::User'; | |
| 18 | |||
| 19 | 6 | primary_column userid => { | |
| 20 | data_type => 'int', | ||
| 21 | is_auto_increment => 1, | ||
| 22 | is_nullable => 0, | ||
| 23 | }; | ||
| 24 | |||
| 25 | 6 | unique_column name => { | |
| 26 | data_type => 'varchar', | ||
| 27 | size => 200, | ||
| 28 | is_nullable => 0, | ||
| 29 | }; | ||
| 30 | |||
| 31 | 6 | column password => { | |
| 32 | data_type => 'char', | ||
| 33 | size => 60, | ||
| 34 | is_nullable => 0, | ||
| 35 | encode_column => 1, | ||
| 36 | encode_class => 'Crypt::Eksblowfish::Bcrypt', | ||
| 37 | encode_args => { key_nul => 1, cost => 8 }, | ||
| 38 | encode_check_method => 'check_password', | ||
| 39 | }; | ||
| 40 | |||
| 41 | 6 | column created_at => { | |
| 42 | data_type => 'datetime', | ||
| 43 | is_nullable => 0, | ||
| 44 | set_on_create => 1, | ||
| 45 | }; | ||
| 46 | |||
| 47 | 6 | column updated_at => { | |
| 48 | data_type => 'datetime', | ||
| 49 | is_nullable => 1, | ||
| 50 | set_on_create => 1, | ||
| 51 | set_on_update => 1, | ||
| 52 | }; | ||
| 53 | |||
| 54 | 6 | unique_column email => { | |
| 55 | data_type => 'varchar', | ||
| 56 | size => 255, | ||
| 57 | is_nullable => 1, | ||
| 58 | }; | ||
| 59 | |||
| 60 | 6 | has_many 'entries' => 'Grimlock::Schema::Result::Entry', { | |
| 61 | 'foreign.author' => 'self.userid', | ||
| 62 | }; | ||
| 63 | |||
| 64 | 6 | has_many 'drafts' => 'Grimlock::Schema::Result::Entry', { | |
| 65 | 'foreign.author' => 'self.userid', | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | 'foreign.published' => undef | ||
| 69 | }; | ||
| 70 | |||
| 71 | 6 | has_many 'user_roles' => 'Grimlock::Schema::Result::UserRole', { | |
| 72 | 'foreign.userid' => 'self.userid' | ||
| 73 | }; | ||
| 74 | |||
| 75 | 6 | many_to_many 'roles' => 'user_roles', 'role'; | |
| 76 | |||
| 77 | 5 | ▶ | sub insert { |
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
documented
| |||
| 78 | 5 | my ( $self, @args ) = @_; | |
| 79 | |||
| 80 | 5 | my $guard = $self->result_source->schema->txn_scope_guard; | |
| 81 | 5 | $self->next::method(@args); | |
| 82 | 5 | $self->add_to_roles({ name => "user" }); | |
| 83 | 5 | $guard->commit; | |
| 84 | |||
| 85 | 5 | return $self; | |
| 86 | } | ||
| 87 | |||
| 88 | 6 | ▶ | sub has_role { |
|
Subroutine
has_role: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 89 | 6 | my ( $self, $role ) = @_; | |
| 90 | 6 | return $self->user_roles->search_related('role', | |
| 91 | { | ||
| 92 | name => $role | ||
| 93 | } | ||
| 94 | )->count; | ||
| 95 | } | ||
| 96 | |||
| 97 | 3 | ▶ | sub entry_count { |
|
Subroutine
entry_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 98 | 3 | my $self = shift; | |
| 99 | 3 | return $self->entries->count; | |
| 100 | } | ||
| 101 | |||
| 102 | 3 | ▶ | sub reply_count { |
|
Subroutine
reply_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 103 | 3 | my $self = shift; | |
| 104 | 3 | return $self->entries->search({ parent => { '!=', undef }})->count; | |
| 105 | } | ||
| 106 | |||
| 107 | 1 | ▶ | sub generate_random_pass { |
|
Subroutine
generate_random_pass: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 108 | 1 | my $self = shift; | |
| 109 | 1 | Text::Password::Pronounceable->generate(6,10); | |
| 110 | } | ||
| 111 | |||
| 112 | 1 | ▶ | sub create_entry { |
|
Subroutine
create_entry: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 113 | 1 | my ( $self, $params ) = @_; | |
| 114 | 1 | return $self->entries->update_or_create($params, | |
| 115 | { | ||
| 116 | key => 'entries_title' | ||
| 117 | } | ||
| 118 | ); | ||
| 119 | } | ||
| 120 | |||
| 121 | 0 | ▶ | sub TO_JSON { |
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 122 | 0 | my $self = shift; | |
| 123 | return { | ||
| 124 | created_at => $self->created_at . "", | ||
| 125 | updated_at => $self->updated_at . "", | ||
| 126 | entries => $self->entries_TO_JSON, | ||
| 127 | 0 | %{ $self->next::method }, | |
| 128 | }; | ||
| 129 | } | ||
| 130 | |||
| 131 | 0 | ▶ | sub entries_TO_JSON { |
|
Subroutine
entries_TO_JSON: not called CC=2 SCAR=17.9
Pod
undocumented
| |||
| 132 | 0 | my $self = shift; | |
| 133 | 0 | my $entry_rs = $self->entries; | |
| 134 | 0 | my @entry_collection; | |
| 135 | push @entry_collection, { | ||
| 136 | entryid => $_->entryid, | ||
| 137 | title => $_->title, | ||
| 138 | 0 | } for $entry_rs->all; | |
| 139 | |||
| 140 | 0 | return \@entry_collection; | |
| 141 | } | ||
| 142 | |||
| 143 | 16 | ▶ | sub draft_count { |
|
Subroutine
draft_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 144 | 16 | my $self = shift; | |
| 145 | 16 | return $self->drafts->count; | |
| 146 | } | ||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | 6 | 1; | |