| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Siebel::Srvrmgr::Daemon::ActionStash; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =pod | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Siebel::Srvrmgr::Daemon::ActionStash - singleton to stash data returned by Siebel::Srvrmgr::Daemon::Action subclasses | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | package MyAction; | 
| 12 |  |  |  |  |  |  | use Moose; | 
| 13 |  |  |  |  |  |  | use namespace::autoclean; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | extends 'Siebel::Srvrmgr::Daemon::Action'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | my $stash = Siebel::Srvrmgr::Daemon::ActionStash->instance(); | 
| 18 |  |  |  |  |  |  | $stash->set_stash([{foobar => foobar}, [qw(one two three)]]); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | package main; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | my $stash = Siebel::Srvrmgr::Daemon::ActionStash->instance(); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # do something with the get_stash method | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | This class was created to enable the possibility to retrieve data from an L<Siebel::Srvrmgr::Daemon::Action> subclass invoked by L<Siebel::Srvrmg::Daemon> without | 
| 29 |  |  |  |  |  |  | the need to return data from within the objects. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | Since Siebel::Srvrmgr::Daemon::ActionStash is a singleton, a reference of the already instantied object will always be returned when calling C<instance>. So, before | 
| 32 |  |  |  |  |  |  | calling the method C<run> from a L<Siebel::Srvrmgr::Daemon> class instance, it is just a matter to call C<instance> and inside the L<Siebel::Srvrmgr::Daemon::Action> subclass, | 
| 33 |  |  |  |  |  |  | call the C<initialize> method with the data that should be returned as parameter. | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | The drawnback from this technique is that two Action objects cannot used the same Stash at the same time or data will be replace/lost: a ActionStash instance should be used | 
| 36 |  |  |  |  |  |  | exclusively by a single Action subclass. If you have need to returned data from several L<Siebel::Srvrmgr::Daemon::Action> subclasses you must use a different method. | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | Considering this situation, the interface of this class should be considered experimental and may be changed in the future releases. | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =cut | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 5 |  |  | 5 |  | 6214 | use MooseX::Singleton; | 
|  | 5 |  |  |  |  | 106618 |  | 
|  | 5 |  |  |  |  | 29 |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =pod | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head2 stash | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | This attribute is a array reference of references. This means that it will accept B<any> reference to some data structure that you think it will be | 
| 51 |  |  |  |  |  |  | useful (including objects). | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | If undefined, this attribute will returned an empty array reference. | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =cut | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | has stash => ( | 
| 58 |  |  |  |  |  |  | is       => 'rw', | 
| 59 |  |  |  |  |  |  | isa      => 'ArrayRef[Ref]', | 
| 60 |  |  |  |  |  |  | required => 0, | 
| 61 |  |  |  |  |  |  | reader   => 'get_stash', | 
| 62 |  |  |  |  |  |  | writer   => 'set_stash', | 
| 63 |  |  |  |  |  |  | default  => sub { return [] } | 
| 64 |  |  |  |  |  |  | ); | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =pod | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head1 METHODS | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head2 get_stash | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | Returns the C<stash> attribute array reference. | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head2 set_stash | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | Sets the C<stash> attribute. Expects an array reference as parameter. | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | Beware that such call will complete remove all other data stored in the stash. To add single items, see C<push_stash> method. | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =head2 push_stash | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | Expects as parameter a reference. | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | Pushes a new reference into the C<stash> attribute. | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | If there is no member in the C<stash> attribute, the method C<set_stash> will be invoked to set the attribute. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =cut | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub push_stash { | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 1 |  |  | 1 | 1 | 417 | my $self = shift; | 
| 93 | 1 |  |  |  |  | 3 | my $ref  = shift; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 1 |  |  |  |  | 35 | my $array_ref = $self->get_stash; | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 1 | 50 |  |  |  | 19 | if ( scalar( @{$array_ref} ) > 0 ) { | 
|  | 1 |  |  |  |  | 4 |  | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 1 |  |  |  |  | 2 | push( @{$array_ref}, $ref ); | 
|  | 1 |  |  |  |  | 3 |  | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | else { | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 0 |  |  |  |  | 0 | $self->set_stash( [$ref] ); | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 1 |  |  |  |  | 3 | return 1; | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =head2 shift_stash | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | Shifts the C<stash> attribute, removing the first item in the attribute and returning it. | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | If there is not other member to be shift, it will return undef. | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =cut | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | sub shift_stash { | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 16 |  |  | 16 | 1 | 1179 | my $self = shift; | 
| 123 |  |  |  |  |  |  |  | 
| 124 | 16 |  |  |  |  | 30 | return shift( @{ $self->get_stash() } ); | 
|  | 16 |  |  |  |  | 530 |  | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =over | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =item * | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | L<Siebel::Srvrmgr::Daemon::Action> | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =item * | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | L<MooseX::Singleton> | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =back | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =head1 AUTHOR | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>. | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>. | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | This file is part of Siebel Monitoring Tools. | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | Siebel Monitoring Tools is free software: you can redistribute it and/or modify | 
| 153 |  |  |  |  |  |  | it under the terms of the GNU General Public License as published by | 
| 154 |  |  |  |  |  |  | the Free Software Foundation, either version 3 of the License, or | 
| 155 |  |  |  |  |  |  | (at your option) any later version. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | Siebel Monitoring Tools is distributed in the hope that it will be useful, | 
| 158 |  |  |  |  |  |  | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 159 |  |  |  |  |  |  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 160 |  |  |  |  |  |  | GNU General Public License for more details. | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | You should have received a copy of the GNU General Public License | 
| 163 |  |  |  |  |  |  | along with Siebel Monitoring Tools.  If not, see L<http://www.gnu.org/licenses/>. | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | =cut | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | 1; |