| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | # (c) 2009 by Murat Uenalan. All rights reserved. Note: This program is | 
| 3 |  |  |  |  |  |  | # free software; you can redistribute it and/or modify it under the same | 
| 4 |  |  |  |  |  |  | # terms as perl itself | 
| 5 |  |  |  |  |  |  | package Class::Maker::Exception; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = "0.06";  # our $VERSION = '0.0.2'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 11032 | use Error qw(:try); | 
|  | 2 |  |  |  |  | 18586 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 2 |  |  | 2 |  | 412 | use Exporter; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 323 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Class::Maker::class | 
| 14 |  |  |  |  |  |  | { | 
| 15 |  |  |  |  |  |  | isa => [qw( Error )], | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | public => | 
| 18 |  |  |  |  |  |  | { | 
| 19 |  |  |  |  |  |  | string => [qw( text package file )], | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | integer => [qw( line )], | 
| 22 |  |  |  |  |  |  | }, | 
| 23 |  |  |  |  |  |  | }; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub _postinit | 
| 26 |  |  |  |  |  |  | { | 
| 27 | 0 |  |  | 0 |  |  | my $this = shift; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 |  |  |  |  |  | local $Error::Depth = $Error::Depth + 1; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | my %h; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  |  |  |  | @h{ qw( package file line ) } = caller( $Error::Depth ); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 0 |  |  |  |  |  | foreach ( qw( package file line ) ) | 
| 36 |  |  |  |  |  |  | { | 
| 37 | 0 | 0 |  |  |  |  | $this->$_( $h{$_} ) unless $this->$_(); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | return $this; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | 1; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | __END__ | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | =head1 NAME | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | Class::Maker::Exception - exceptions tuned for Class::Maker | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | use Class::Maker qw(class); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | use Class::Maker::Exception qw(:try); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | { | 
| 58 |  |  |  |  |  |  | package Exception::Child; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | Class::Maker::class | 
| 61 |  |  |  |  |  |  | { | 
| 62 |  |  |  |  |  |  | isa => [qw( Class::Maker::Exception )], | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | public => | 
| 65 |  |  |  |  |  |  | { | 
| 66 |  |  |  |  |  |  | string => [qw( email )], | 
| 67 |  |  |  |  |  |  | }, | 
| 68 |  |  |  |  |  |  | }; | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | package Exception::ChildChild; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | Class::Maker::class | 
| 73 |  |  |  |  |  |  | { | 
| 74 |  |  |  |  |  |  | isa => [qw( Exception::Child )], | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | public => | 
| 77 |  |  |  |  |  |  | { | 
| 78 |  |  |  |  |  |  | string => [qw( name )], | 
| 79 |  |  |  |  |  |  | }, | 
| 80 |  |  |  |  |  |  | }; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub do_some_stuff | 
| 84 |  |  |  |  |  |  | { | 
| 85 |  |  |  |  |  |  | Exception::ChildChild->throw( email => 'bla@bla.de', name => 'johnny' ); | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | return; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | try | 
| 91 |  |  |  |  |  |  | { | 
| 92 |  |  |  |  |  |  | do_some_stuff(); | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | catch Exception::ChildChild with | 
| 96 |  |  |  |  |  |  | { | 
| 97 |  |  |  |  |  |  | foreach my $e (@_) | 
| 98 |  |  |  |  |  |  | { | 
| 99 |  |  |  |  |  |  | print Dumper $e; | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  | }; | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | This is mainly a wrapper to "Error" from CPAN. Because it has a very odd inheritance mechanism, | 
| 106 |  |  |  |  |  |  | this wrapper is needed as a workarround. | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =head1 BUGS | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | Not critical: The "text" attribute is not working. Reading/Writing to it somehow goes into nirvana. | 
| 111 |  |  |  |  |  |  | I suppose "Error" has same clue about it. Would suggest to inherit from Class::Maker::Exception and add | 
| 112 |  |  |  |  |  |  | and new "info_text" attribute, which will work. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =head1 BASE CLASSES | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head2 Class::Maker::Exception | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | Has following structure (and inheritable attributes). | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | class | 
| 121 |  |  |  |  |  |  | { | 
| 122 |  |  |  |  |  |  | isa => [qw( Error )], | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | public => | 
| 125 |  |  |  |  |  |  | { | 
| 126 |  |  |  |  |  |  | string => [qw( text package file )], | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | integer => [qw( line )], | 
| 129 |  |  |  |  |  |  | }, | 
| 130 |  |  |  |  |  |  | }; | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head1 AUTHOR | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | Murat Uenalan | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | L<Error> | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =cut | 
| 141 |  |  |  |  |  |  |  |