| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package JE::Object::Error; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = '0.064'; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 101 |  |  | 101 |  | 19481 | use strict; | 
|  | 101 |  |  |  |  | 114 |  | 
|  | 101 |  |  |  |  | 3182 |  | 
| 7 | 101 |  |  | 101 |  | 392 | use warnings; | 
|  | 101 |  |  |  |  | 115 |  | 
|  | 101 |  |  |  |  | 57151 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our @ISA = 'JE::Object'; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | require JE::Object; | 
| 12 |  |  |  |  |  |  | require JE::String; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # ~~~ Need to add support for line number, script name, etc., or perhaps | 
| 16 |  |  |  |  |  |  | #     just a reference to the corresponding JE::Code object. | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 NAME | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | JE::Object::Error - JavaScript Error object class | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | use JE::Object::Error; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # Somewhere in code called by an eval{} | 
| 27 |  |  |  |  |  |  | die new JE::Object::Error $global, "(Error message here)"; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | # Later: | 
| 30 |  |  |  |  |  |  | $@->prop('message');  # error message | 
| 31 |  |  |  |  |  |  | $@->prop('name');     # 'Error' | 
| 32 |  |  |  |  |  |  | "$@";                 # 'Error: ' plus the error message | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | This class implements JavaScript Error objects for JE. This is the base | 
| 37 |  |  |  |  |  |  | class for all JavaScript's native error objects. (See L, below.) | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =head1 METHODS | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | See L for descriptions of most of the methods. Only what | 
| 42 |  |  |  |  |  |  | is specific to JE::Object::Error is explained here. | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | The C method returns the string S<'Error: '> followed by the error | 
| 45 |  |  |  |  |  |  | message. 'Error' will be replaced with the class name (the result of | 
| 46 |  |  |  |  |  |  | calling | 
| 47 |  |  |  |  |  |  | C<< ->class >>) for subclasses. | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =cut | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub new { | 
| 52 | 340 |  |  | 340 | 1 | 725 | my($class, $global, $val) = @_; | 
| 53 | 340 |  |  |  |  | 1338 | my($js_class) = $class->name; | 
| 54 | 340 |  | 33 |  |  | 1444 | my $self = $class->SUPER::new($global, { | 
| 55 |  |  |  |  |  |  | prototype => $global->prototype_for($js_class) || | 
| 56 |  |  |  |  |  |  | $global->prop($js_class)->prop('prototype') | 
| 57 |  |  |  |  |  |  | }); | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 340 | 100 | 66 |  |  | 3251 | $self->prop({ | 
| 60 |  |  |  |  |  |  | dontenum => 1, | 
| 61 |  |  |  |  |  |  | name => 'message', | 
| 62 |  |  |  |  |  |  | value => JE::String->_new($global, $val), | 
| 63 |  |  |  |  |  |  | }) if defined $val and ref $val ne 'JE::Undefined'; | 
| 64 | 340 |  |  |  |  | 3178 | $self; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  | 0 | 1 | 0 | sub value { $_[0]->method('toString')->value } | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 44 |  |  | 44 | 1 | 116 | sub class { 'Error' } | 
| 70 |  |  |  |  |  |  | *name = *class; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub _new_constructor { | 
| 73 | 34 |  |  | 34 |  | 70 | my $global = shift; | 
| 74 |  |  |  |  |  |  | my $con = sub { | 
| 75 | 8 |  |  | 8 |  | 48 | __PACKAGE__->new(@_); | 
| 76 | 34 |  |  |  |  | 142 | }; | 
| 77 | 34 |  |  |  |  | 100 | my $args = ['scope','args']; | 
| 78 | 34 |  |  |  |  | 340 | my $f = JE'Object'Function->new({ | 
| 79 |  |  |  |  |  |  | name             => 'Error', | 
| 80 |  |  |  |  |  |  | scope            => $global, | 
| 81 |  |  |  |  |  |  | argnames         => ['message'], | 
| 82 |  |  |  |  |  |  | function         => $con, | 
| 83 |  |  |  |  |  |  | function_args    => $args, | 
| 84 |  |  |  |  |  |  | constructor      => $con, | 
| 85 |  |  |  |  |  |  | constructor_args => $args, | 
| 86 |  |  |  |  |  |  | }); | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 34 |  |  |  |  | 207 | my $proto = bless $f->prop({ | 
| 89 |  |  |  |  |  |  | name => 'prototype', dontenum => 1, readonly => 1 | 
| 90 |  |  |  |  |  |  | }); | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 34 |  |  |  |  | 148 | $global->prototype_for('Error',$proto); | 
| 93 |  |  |  |  |  |  | $proto->prop({ | 
| 94 |  |  |  |  |  |  | name  => 'toString', | 
| 95 |  |  |  |  |  |  | value => JE::Object::Function->new({ | 
| 96 |  |  |  |  |  |  | scope  => $global, | 
| 97 |  |  |  |  |  |  | name   => 'toString', | 
| 98 |  |  |  |  |  |  | length => 0, | 
| 99 |  |  |  |  |  |  | function_args => ['this'], | 
| 100 |  |  |  |  |  |  | function => sub { | 
| 101 | 29 |  |  | 29 |  | 41 | my $self = shift; | 
| 102 | 29 |  |  |  |  | 91 | JE::String->_new( | 
| 103 |  |  |  |  |  |  | $$$self{global}, | 
| 104 |  |  |  |  |  |  | $self->prop( | 
| 105 |  |  |  |  |  |  | 'name' | 
| 106 |  |  |  |  |  |  | ) . | 
| 107 |  |  |  |  |  |  | ': ' . | 
| 108 |  |  |  |  |  |  | $self->prop( | 
| 109 |  |  |  |  |  |  | 'message'							) | 
| 110 |  |  |  |  |  |  | ); | 
| 111 |  |  |  |  |  |  | } | 
| 112 | 34 |  |  |  |  | 336 | }), | 
| 113 |  |  |  |  |  |  | dontenum => 1, | 
| 114 |  |  |  |  |  |  | }); | 
| 115 | 34 |  |  |  |  | 272 | $proto->prop({ | 
| 116 |  |  |  |  |  |  | name  => 'name', | 
| 117 |  |  |  |  |  |  | value => JE::String->_new($global, 'Error'), | 
| 118 |  |  |  |  |  |  | dontenum => 1, | 
| 119 |  |  |  |  |  |  | }); | 
| 120 | 34 |  |  |  |  | 140 | $proto->prop({ | 
| 121 |  |  |  |  |  |  | name  => 'message', | 
| 122 |  |  |  |  |  |  | value => JE::String->_new($global, | 
| 123 |  |  |  |  |  |  | 'Unknown error'), | 
| 124 |  |  |  |  |  |  | dontenum => 1, | 
| 125 |  |  |  |  |  |  | }); | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 34 |  |  |  |  | 135 | weaken $global; | 
| 128 | 34 |  |  |  |  | 277 | $f | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | sub _new_subclass_constructor { | 
| 132 | 42 |  |  | 42 |  | 89 | my($package,$global) = @_; | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | my $f = JE::Object::Function->new({ | 
| 135 |  |  |  |  |  |  | name             => my $name = $package->name, | 
| 136 |  |  |  |  |  |  | scope            => $global, | 
| 137 |  |  |  |  |  |  | argnames         => ['message'], | 
| 138 | 38 |  |  | 38 |  | 148 | function         =>(sub { $package->new(@_) }, | 
| 139 | 42 |  |  |  |  | 180 | function_args    => ['scope','args'], | 
| 140 |  |  |  |  |  |  | constructor      => #  " | 
| 141 |  |  |  |  |  |  | constructor_args => #  " | 
| 142 |  |  |  |  |  |  | )[ 0..3,0,4,2 ], | 
| 143 |  |  |  |  |  |  | }); | 
| 144 |  |  |  |  |  |  |  | 
| 145 | 42 |  |  |  |  | 258 | my $proto = $f->prop({ | 
| 146 |  |  |  |  |  |  | name    => 'prototype', | 
| 147 |  |  |  |  |  |  | dontenum => 1, | 
| 148 |  |  |  |  |  |  | readonly => 1, | 
| 149 |  |  |  |  |  |  | }); | 
| 150 | 42 |  |  |  |  | 158 | $global->prototype_for($name=>$proto); | 
| 151 | 42 |  |  |  |  | 131 | bless $proto, $package; | 
| 152 | 42 |  | 33 |  |  | 114 | $proto->prototype( | 
| 153 |  |  |  |  |  |  | $global->prototype_for('Error') | 
| 154 |  |  |  |  |  |  | || $global->prop('Error')->prop('prototype') | 
| 155 |  |  |  |  |  |  | ); | 
| 156 | 42 |  |  |  |  | 201 | $proto->prop({ | 
| 157 |  |  |  |  |  |  | name  => 'name', | 
| 158 |  |  |  |  |  |  | value => JE::String->_new($global, $name), | 
| 159 |  |  |  |  |  |  | dontenum => 1, | 
| 160 |  |  |  |  |  |  | }); | 
| 161 | 42 |  |  |  |  | 475 | (my $msg = $name) =~ s/(?!^)([A-Z])(?![A-Z])/ \l$1/g; | 
| 162 | 42 |  |  |  |  | 266 | $proto->prop({ | 
| 163 |  |  |  |  |  |  | name  => 'message', | 
| 164 |  |  |  |  |  |  | value => JE::String->_new($global, $msg), | 
| 165 |  |  |  |  |  |  | dontenum => 1, | 
| 166 |  |  |  |  |  |  | }); | 
| 167 |  |  |  |  |  |  |  | 
| 168 | 42 |  |  |  |  | 145 | weaken $global; | 
| 169 | 42 |  |  |  |  | 343 | $f; | 
| 170 |  |  |  |  |  |  | } | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | return "a true value"; | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =over 4 | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =item L | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =item L | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =item L | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | =item L | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =item L | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =item L | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | =item L | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =back | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =cut | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  |  |