File Coverage

blib/lib/Mojo/Snoo/Comment.pm
Criterion Covered Total %
statement 7 7 100.0
branch 1 2 50.0
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 11 13 84.6


line stmt bran cond sub pod time code
1             package Mojo::Snoo::Comment;
2 5     5   25 use Moo;
  5         6  
  5         20  
3              
4             extends 'Mojo::Snoo::Base';
5              
6 5     5   1113 use constant FIELD => 'id';
  5         5  
  5         977  
7              
8             has id => (
9             is => 'ro',
10             isa => sub {
11             die "Comment needs ID!" unless $_[0];
12             },
13             required => 1
14             );
15              
16             has [qw( author body )] => (is => 'ro');
17              
18             has replies => (
19             is => 'rw',
20             coerce => sub {
21             my $replies = shift;
22              
23             # comments without replies contain " "
24             my $children = ref($replies) ? $replies->{data}{children} : [];
25             return Mojo::Collection->new(
26             map {
27             $_->{kind} eq 't1' # unloaded comments have type 'more'
28             ? Mojo::Snoo::Comment->new(%{$_->{data}})
29             : ()
30             } @$children
31             );
32             },
33             );
34              
35             # let the user call the constructor using new($comment) or new(id => $comment)
36 1 50   1 0 1785 sub BUILDARGS { shift->SUPER::BUILDARGS(@_ == 1 ? (id => shift) : @_) }
37              
38             1;
39              
40             __END__