Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

timestamps and docs

  • Loading branch information...
commit 990b1cef117f46e4d7bac3841a8e7711b3ffda46 1 parent 88364ed
@monken monken authored
Showing with 118 additions and 18 deletions.
  1. +27 −7 lib/MetaCPAN/Document/Favorite.pm
  2. +91 −11 lib/MetaCPAN/Model/User/Account.pm
View
34 lib/MetaCPAN/Document/Favorite.pm
@@ -5,18 +5,38 @@ use MetaCPAN::Types qw(:all);
use DateTime;
use MetaCPAN::Util;
-has id => ( is => 'ro', id => [qw(user distribution)] );
-has [qw(author release user distribution)] => ( is => 'ro', required => 1 );
+has id => (
+ is => 'ro',
+ id => [qw(user distribution)],
+);
+
+has [qw(author release user distribution)] => (
+ is => 'ro',
+ required => 1,
+);
+
+=head2 date
+
+L<DateTime> when the item was created.
+
+=cut
+
has date => (
is => 'ro',
required => 1,
isa => 'DateTime',
- default => sub { DateTime->now }
+ default => sub { DateTime->now },
);
-sub _build_release_id {
- my $self = shift;
- return MetaCPAN::Util::digest( $self->author, $self->release );
-}
+=head2 timestamp
+
+Sets the C<_timestamp> field to the value of L</date>.
+
+=cut
+
+has timestamp => (
+ is => 'ro',
+ timestamp => { path => 'date', store => 1 },
+);
__PACKAGE__->meta->make_immutable;
View
102 lib/MetaCPAN/Model/User/Account.pm
@@ -7,7 +7,26 @@ use MooseX::Types::Structured qw(Dict);
use MooseX::Types::Moose qw(Str ArrayRef);
use MetaCPAN::Types qw(:all);
-has id => ( id => 1, required => 0, is => 'rw' );
+=head1 PROPERTIES
+
+=head2 id
+
+ID of user account.
+
+=cut
+
+has id => (
+ id => 1,
+ required => 0,
+ is => 'rw',
+);
+
+=head2 identity
+
+Array of L<MetaCPAN::Model::User::Identity> objects. Each identity is a
+authentication provider such as Twitter or GitHub.
+
+=cut
has identity => (
is => 'ro',
@@ -16,10 +35,26 @@ has identity => (
coerce => 1,
traits => ['Array'],
handles => { add_identity => 'push' },
- default => sub { [] }
+ default => sub { [] },
);
-has code => ( is => 'rw', clearer => 'clear_token' );
+=head2 code
+
+The code attribute is used temporarily when authenticating using OAuth.
+
+=cut
+
+has code => (
+ is => 'rw',
+ clearer => 'clear_token',
+);
+
+=head2 access_token
+
+Array of access token that allow third-party applications to authenticate
+as the user.
+
+=cut
has access_token => (
is => 'ro',
@@ -28,40 +63,85 @@ has access_token => (
default => sub { [] },
dynamic => 1,
traits => ['Array'],
- handles => { add_access_token => 'push' }
+ handles => { add_access_token => 'push' },
+);
+
+=head2 passed_captcha
+
+L<DateTime> when the user passed the captcha.
+
+=cut
+
+has passed_captcha => (
+ is => 'rw',
+ isa => 'DateTime',
);
-has passed_captcha => ( is => 'rw', isa => 'DateTime' );
+=head2 looks_human
+
+Certain features are disabled unless a user C<looks_human>. This attribute
+is true if the user is connected to a PAUSE account or he L</passed_captcha>.
+
+=cut
has looks_human => (
is => 'ro',
isa => 'Bool',
required => 1,
lazy_build => 1,
- clearer => 'clear_looks_human'
+ clearer => 'clear_looks_human',
+);
+
+sub _build_looks_human {
+ my $self = shift;
+ return $self->has_identity('pause') || ( $self->passed_captcha ? 1 : 0 );
+}
+
+=head2 timestamp
+
+Sets the C<_timestamp> field.
+
+=cut
+
+has timestamp => (
+ is => 'ro',
+ timestamp => { store => 1 },
);
+=head1 METHODS
+
+=head2 add_identity
+
+Adds an identity to L</identity>. If the identity is a PAUSE account,
+the user ID is added to the corresponding L<MetaCPAN::Document::Author> document
+and L</looks_human> is updated.
+
+=cut
+
after add_identity => sub {
my ( $self, $identity ) = @_;
if ( $identity->{name} eq 'pause' ) {
$self->clear_looks_human;
my $profile = $self->index->model->index('cpan')->type('author')
->get( $identity->{key} );
- $profile->user( $self->id ) if($profile);
+ $profile->user( $self->id ) if ($profile);
$profile->put;
}
};
-sub _build_looks_human {
- my $self = shift;
- return $self->has_identity('pause') || ($self->passed_captcha ? 1 : 0);
-}
+=head2 has_identity
+
+=cut
sub has_identity {
my ( $self, $identity ) = @_;
return scalar grep { $_->name eq $identity } @{ $self->identity };
}
+=head2 get_identities
+
+=cut
+
sub get_identities {
my ( $self, $identity ) = @_;
return grep { $_->name eq $identity } @{ $self->identity };
Please sign in to comment.
Something went wrong with that request. Please try again.