| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::HTTP::Spore::Meta::Method::Spore; | 
| 2 |  |  |  |  |  |  | $Net::HTTP::Spore::Meta::Method::Spore::VERSION = '0.09'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: declare API method | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 22 |  |  | 22 |  | 11047 | use Moose::Role; | 
|  | 22 |  |  |  |  | 56 |  | 
|  | 22 |  |  |  |  | 129 |  | 
| 6 | 22 |  |  | 22 |  | 101044 | use Carp qw/confess/; | 
|  | 22 |  |  |  |  | 55 |  | 
|  | 22 |  |  |  |  | 1192 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 22 |  |  | 22 |  | 7164 | use Net::HTTP::Spore::Meta::Method; | 
|  | 22 |  |  |  |  | 84 |  | 
|  | 22 |  |  |  |  | 1281 |  | 
| 9 | 22 |  |  | 22 |  | 204 | use MooseX::Types::Moose qw/Str ArrayRef/; | 
|  | 22 |  |  |  |  | 48 |  | 
|  | 22 |  |  |  |  | 217 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | has local_spore_methods => ( | 
| 12 |  |  |  |  |  |  | traits     => ['Array'], | 
| 13 |  |  |  |  |  |  | is         => 'rw', | 
| 14 |  |  |  |  |  |  | isa        => ArrayRef [Str], | 
| 15 |  |  |  |  |  |  | required   => 1, | 
| 16 |  |  |  |  |  |  | default    => sub { [] }, | 
| 17 |  |  |  |  |  |  | auto_deref => 1, | 
| 18 |  |  |  |  |  |  | handles    => { | 
| 19 |  |  |  |  |  |  | _find_spore_method_by_name => 'first', | 
| 20 |  |  |  |  |  |  | _add_spore_method          => 'push', | 
| 21 |  |  |  |  |  |  | get_all_spore_methods      => 'elements', | 
| 22 |  |  |  |  |  |  | }, | 
| 23 |  |  |  |  |  |  | ); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub find_spore_method_by_name { | 
| 26 | 27 |  |  | 27 | 1 | 702 | my ($meta, $name) = @_; | 
| 27 | 27 |  |  | 72 |  | 1295 | my $method_name = $meta->_find_spore_method_by_name(sub {/^$name$/}); | 
|  | 72 |  |  |  |  | 678 |  | 
| 28 | 27 | 50 |  |  |  | 160 | return unless $method_name; | 
| 29 | 27 |  |  |  |  | 210 | my $method = $meta->find_method_by_name($method_name); | 
| 30 | 27 | 50 |  |  |  | 1740 | if ($method->isa('Class::MOP::Method::Wrapped')) { | 
| 31 | 27 |  |  |  |  | 136 | return $method->get_original_method; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | else { | 
| 34 | 0 |  |  |  |  | 0 | return $method; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub remove_spore_method { | 
| 39 | 0 |  |  | 0 | 1 | 0 | my ($meta, $name) = @_; | 
| 40 | 0 |  |  |  |  | 0 | my @methods = grep { $_ ne $name } $meta->get_all_spore_methods; | 
|  | 0 |  |  |  |  | 0 |  | 
| 41 | 0 |  |  |  |  | 0 | $meta->local_spore_methods(\@methods); | 
| 42 | 0 |  |  |  |  | 0 | $meta->remove_method($name); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | before add_spore_method => sub { | 
| 46 |  |  |  |  |  |  | my ($meta, $name) = @_; | 
| 47 |  |  |  |  |  |  | if ($meta->_find_spore_method_by_name(sub {$_ eq $name})) { | 
| 48 |  |  |  |  |  |  | confess "method '$name' is already delcared in ".$meta->name; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | }; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub add_spore_method { | 
| 53 | 127 |  |  | 127 | 1 | 1257 | my ($meta, $name, %options) = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 127 |  |  |  |  | 302 | my $code = delete $options{code}; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | # $meta->_trace_msg( '-> attach ' | 
| 58 |  |  |  |  |  |  | #       . $name . ' (' | 
| 59 |  |  |  |  |  |  | #       . $options{method} . ' => ' | 
| 60 |  |  |  |  |  |  | #       . $options{path} | 
| 61 |  |  |  |  |  |  | #       . ')' ); | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 127 |  |  |  |  | 1037 | $meta->add_method( | 
| 64 |  |  |  |  |  |  | $name, | 
| 65 |  |  |  |  |  |  | Net::HTTP::Spore::Meta::Method->wrap( | 
| 66 |  |  |  |  |  |  | name         => $name, | 
| 67 |  |  |  |  |  |  | package_name => $meta->name, | 
| 68 |  |  |  |  |  |  | body         => $code, | 
| 69 |  |  |  |  |  |  | %options | 
| 70 |  |  |  |  |  |  | ), | 
| 71 |  |  |  |  |  |  | ); | 
| 72 | 125 |  |  |  |  | 214864 | $meta->_add_spore_method($name); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | after add_spore_method => sub { | 
| 76 |  |  |  |  |  |  | my ($meta, $name) = @_; | 
| 77 |  |  |  |  |  |  | $meta->add_before_method_modifier( | 
| 78 |  |  |  |  |  |  | $name, | 
| 79 |  |  |  |  |  |  | sub { | 
| 80 |  |  |  |  |  |  | my $self = shift; | 
| 81 |  |  |  |  |  |  | die Net::HTTP::Spore::Response->new(599, [], {error => "'base_url' have not been defined"}) unless $self->base_url; | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  | ); | 
| 84 |  |  |  |  |  |  | }; | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | 1; | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | __END__ | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =pod | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =encoding UTF-8 | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =head1 NAME | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | Net::HTTP::Spore::Meta::Method::Spore - declare API method | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head1 VERSION | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | version 0.09 | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | my $api_client = MyAPI->new; | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | my @methods    = $api_client->meta->get_all_api_methods(); | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | my $method     = $api_client->meta->find_spore_method_by_name('users'); | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | $api_client->meta->remove_spore_method($method); | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | $api_client->meta->add_spore_method('users', sub {...}, | 
| 113 |  |  |  |  |  |  | description => 'this method does...',); | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 METHODS | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head2 get_all_spore_methods | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | Return a list of net api methods | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =head2 find_spore_method_by_name | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | Return a net api method | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head2 remove_spore_method | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | Remove a net api method | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =head2 add_spore_method | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | Add a net api method | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =head1 AUTHORS | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =over 4 | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =item * | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | Franck Cuny <franck.cuny@gmail.com> | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =item * | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Ash Berlin <ash@cpan.org> | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =item * | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | Ahmad Fatoum <athreef@cpan.org> | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =back | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This software is copyright (c) 2012 by Linkfluence. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 158 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =cut |