File Coverage

blib/lib/Net/OpenSocial/Client/ErrorHandler.pm
Criterion Covered Total %
statement 3 8 37.5
branch n/a
condition n/a
subroutine 1 3 33.3
pod 2 2 100.0
total 6 13 46.1


line stmt bran cond sub pod time code
1             package Net::OpenSocial::Client::ErrorHandler;
2              
3 1     1   469 use Any::Moose '::Role';
  1         2  
  1         5  
4              
5             has '_errstr' => (
6             is => 'rw',
7             isa => 'Str',
8             );
9              
10             sub ERROR {
11 0     0 1   my ( $self, $message ) = @_;
12 0           $self->_errstr($message);
13 0           return;
14             }
15              
16             sub errstr {
17 0     0 1   my $self = shift;
18 0           return $self->_errstr;
19             }
20              
21             1;
22              
23             =head1 NAME
24              
25             Net::OpenSocial::Client::ErrorHandler - Error handler role
26              
27             =head1 SYNOPSIS
28              
29             package MyClass;
30             use Any::Moose;
31             with 'Net::OpenSocial::Client::ErrorHandler';
32             sub my_method {
33             my $self = shift;
34             if ( $self->found_any_error ) {
35             return $self->ERROR('Error occured.');
36             }
37             return 1;
38             }
39              
40             package main;
41             use MyClass;
42             my $foo = MyClass->new;
43             my $result = $foo->my_method
44             or die $foo->errstr;
45              
46             =head1 DESCRIPTION
47              
48             Error handler role.
49             This provides a simple way to handle error.
50              
51             =head1 METHODS
52              
53             =head2 ERROR( $message )
54              
55             When some error occured, call like that
56              
57             return $self->ERROR($error_message);
58              
59             And this returns undef.
60             After that, you can pick up the error message by calling 'errstr' method.
61              
62             =head2 errstr
63              
64             If it already called 'ERROR' method, it returns an error message.
65              
66             die $self->errstr;
67              
68             =head1 SEE ALSO
69              
70             L
71              
72             =head1 AUTHOR
73              
74             Lyo Kato, Elyo.kato@gmail.comE
75              
76             =head1 COPYRIGHT AND LICENSE
77              
78             Copyright (C) 2009 by Lyo Kato
79              
80             This library is free software; you can redistribute it and/or modify
81             it under the same terms as Perl itself, either Perl version 5.8.8 or,
82             at your option, any later version of Perl 5 you may have available.
83              
84             =cut
85