| 1 | package Net::Zuora::ZObject::Role; | ||
| 2 | use Moose::Role; | ||
| 3 | use MooseX::Types::Moose qw/Bool Str/; | ||
| 4 | use namespace::autoclean; | ||
| 5 | |||
| 6 | has _api => ( isa => 'Net::Zuora', is => 'ro', required => 1, weak_ref => 1 ); | ||
| 7 | has _created => ( isa => Bool, default => 0, is => 'ro' ); | ||
| 8 | |||
| 9 | has Id => ( isa => Str, is => 'ro', predicate => 'has_Id', | ||
| 10 | traits => [qw/Net::Zuora::ZObject::AttributeRole/], | ||
| 11 | index => -1, | ||
| 12 | ); | ||
| 13 | |||
| 14 | sub create { | ||
| 15 | my ($self) = @_; | ||
| 16 | Carp::confess("Object $self already exists in Zuora system") | ||
| 17 | if $self->_created; | ||
| 18 | my $res = $self->_api->_do_create($self); | ||
| 19 | # Force write to ro attribute via MOP. | ||
| 20 | $self->meta->find_attribute_by_name('_created')->set_value($self, 1); | ||
| 21 | return $res; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub update { | ||
| 25 | my ($self) = @_; | ||
| 26 | Carp::confess("Object $self does not exist in Zuora system") | ||
| 27 | unless $self->_created; | ||
| 28 | $self->_api->_do_update($self); | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; | ||
| 32 | |||
| 33 | =head1 NAME | ||
| 34 | |||
| 35 | Net::Zuora::ZObject::Role - Moose role representing an object in the Zuora system | ||
| 36 | |||
| 37 | =head1 DESCRIPTION | ||
| 38 | |||
| 39 | This is a base L<Moose::Role|role> which all objects that are represented | ||
| 40 | in the Zuora API consume. | ||
| 41 | |||
| 42 | =head1 METHODS | ||
| 43 | |||
| 44 | =head2 create | ||
| 45 | |||
| 46 | Creates an object which does not exist already in the Zuora's API. | ||
| 47 | |||
| 48 | Throws an exception if the object could not be created for any reason. | ||
| 49 | |||
| 50 | =head2 update | ||
| 51 | |||
| 52 | Pushes any local updates to this object back to Zuora's API. | ||
| 53 | |||
| 54 | Throws an exception if the object could not be updated for any reason. | ||
| 55 | |||
| 56 | =head1 ZUORA DOCS | ||
| 57 | |||
| 58 | L<http://apidocs.developer.zuora.com/index.php/ZObject> | ||
| 59 | |||
| 60 | =head1 AUTHOR | ||
| 61 | |||
| 62 | See L<Net::Zuora> for author information | ||
| 63 | |||
| 64 | =head1 COPYRIGHT & LICENSE | ||
| 65 | |||
| 66 | See L<Net::Zuora> for copyright and license information. | ||
| 67 | |||
| 68 | =cut | ||
| 69 |