| 1 | package WebService::MyGengo::Comment; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | use Moose::Util::TypeConstraints; | ||
| 5 | # This interferes with stringification overload | ||
| 6 | # See https://rt.cpan.org/Public/Bug/Display.html?id=50938 | ||
| 7 | #use namespace::autoclean; | ||
| 8 | |||
| 9 | BEGIN { extends 'WebService::MyGengo::Base' }; | ||
| 10 | |||
| 11 | # Stringify to the comment body | ||
| 12 | use overload ( '""' => sub { shift->body } ); | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | WebService::MyGengo::Comment - A Comment in the myGengo system. | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | my $comment = WebService::MyGengo::Comment->new( { body => 'Hello.' } ); | ||
| 21 | # or | ||
| 22 | $comment = WebService::MyGengo::Comment->new( 'Hello.' ); | ||
| 23 | |||
| 24 | # Do something with the Comment | ||
| 25 | $job = $client->add_job_comment( $job, $comment ); | ||
| 26 | |||
| 27 | # Returns ->body on stringification | ||
| 28 | my $body = "$comment"; # $body eq "Hello." | ||
| 29 | |||
| 30 | =head1 ATTRIBUTES | ||
| 31 | |||
| 32 | =head2 body (Str) | ||
| 33 | |||
| 34 | The body of the comment in UTF-8 encoding. | ||
| 35 | |||
| 36 | B<Note:> Sometimes the API returns 'null' (undef) for this value. In this case | ||
| 37 | the value will be coerced into an empty string. | ||
| 38 | |||
| 39 | =cut | ||
| 40 | subtype 'WebService::MyGengo::Comment::body' | ||
| 41 | , as 'Str'; | ||
| 42 | coerce 'WebService::MyGengo::Comment::body' | ||
| 43 | , from 'Undef', via { '' }; | ||
| 44 | has 'body' => ( | ||
| 45 | is => 'ro' | ||
| 46 | , isa => 'WebService::MyGengo::Comment::body' | ||
| 47 | , required => 1 | ||
| 48 | ); | ||
| 49 | |||
| 50 | =head2 author (Str) | ||
| 51 | |||
| 52 | The author of the message. | ||
| 53 | |||
| 54 | This value is set by the API to one of the following: translator, customer | ||
| 55 | |||
| 56 | =cut | ||
| 57 | subtype 'WebService::MyGengo::CommentAuthor' | ||
| 58 | , as 'Str' | ||
| 59 | , where { $_ eq 'translator' || $_ eq 'customer' } | ||
| 60 | , message { "Legal values for 'author': translator, customer" } | ||
| 61 | ; | ||
| 62 | has 'author' => ( | ||
| 63 | is => 'ro' | ||
| 64 | , isa => 'WebService::MyGengo::CommentAuthor' | ||
| 65 | ); | ||
| 66 | |||
| 67 | =head2 ctime (DateTime) | ||
| 68 | |||
| 69 | The timestamp at which this Comment was created. | ||
| 70 | |||
| 71 | This value is set by the API. | ||
| 72 | |||
| 73 | =cut | ||
| 74 | has 'ctime' => ( | ||
| 75 | is => 'ro' | ||
| 76 | , isa => 'WebService::MyGengo::DateTime' | ||
| 77 | , coerce => 1 | ||
| 78 | ); | ||
| 79 | |||
| 80 | #=head1 METHODS | ||
| 81 | # | ||
| 82 | #=head2 around BUILDARGS | ||
| 83 | # | ||
| 84 | #Allow single-argument constructor for `body` | ||
| 85 | # | ||
| 86 | #=cut | ||
| 87 | around BUILDARGS => sub { | ||
| 88 | my ( $orig, $class, $val ) = ( shift, shift, @_ ); | ||
| 89 | (ref($val) eq 'HASH' || $#_) and return $class->$orig( @_ ); | ||
| 90 | return { body => $val }; | ||
| 91 | }; | ||
| 92 | |||
| 93 | |||
| 94 | no Moose; | ||
| 95 | __PACKAGE__->meta->make_immutable(); | ||
| 96 | |||
| 97 | 1; | ||
| 98 | |||
| 99 | =head2 SEE ALSO | ||
| 100 | |||
| 101 | L<http://mygengo.com/api/developer-docs/methods/translate-job-id-comments-get/> | ||
| 102 | |||
| 103 | =head1 AUTHOR | ||
| 104 | |||
| 105 | Nathaniel Heinrichs | ||
| 106 | |||
| 107 | =head1 LICENSE | ||
| 108 | |||
| 109 | Copyright (c) 2011, Nathaniel Heinrichs <nheinric-at-cpan.org>. | ||
| 110 | All rights reserved. | ||
| 111 | |||
| 112 | This library is free software. You can redistribute it and/or modify | ||
| 113 | it under the same terms as Perl itself. | ||
| 114 | |||
| 115 | =cut |