Object/Hybrid.pm

filter: Statementstmt 57.2% 295 / 515 Branchbran 39.5% 121 / 306 Conditioncond 27.6% 96 / 347 MC/DCmcdc 11.6% 22 / 189 Subroutinesub 50.0% 57 / 114 Podpod 11.7% 4 / 34 totaltotal 39.5% 595 / 1505 CC 282 SCAR 42.3
CC
282
Cov
44%
__ANON__
217.6
__ANON__
217.6
import
202.5
CRAP 68.9
↑ Summary Class/Tag.pm »
1 package Object::Hybrid;
2
3 #use 5.006;
4
5 1 ▶use strict qw[vars subs];
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Object::Hybrid::VERSION = '0.07';
7
8 1 $Object::Hybrid::Class::VERSION = '0';
9 1 $Object::Hybrid::HASH::VERSION = '0';
10 1 $Object::Hybrid::ARRAY::VERSION = '0';
11 1 $Object::Hybrid::GLOB::VERSION = '0';
12 1 $Object::Hybrid::SCALAR::VERSION = '0';
13
14 =head1 NAME
15
16 Object::Hybrid - promote Perl primitives (hashes, scalars, arrays, and filehandles), either tie()d or not, to become hybrid objects
17
18 =head1 WARNING
19
20 Any specific interface that Object::Hybrid exposes may change (as it already did) until version 1.0 is reached.
21
22 =head1 SYNOPSIS
23
24 Here (and everywhere in this documentation) notion of "primitive" refers to hash, scalar, array, or filehandle (i.e. perltie types), either tie()d or non-tie()d, bless()ed or non-bless()ed.
25
26 Promote $primitive to become hybrid object:
27
28 use Object::Hybrid qw(promote); # declare promote() for use
29 promote $primitive;
30
31 Or (especially if you prefer to not export anything) use new() constructor...
32
33 use Object::Hybrid;
34 $hybrid = new Object::Hybrid $primitive; # $primitive becomes hybrid object
35 $hybrid = Object::Hybrid->new($primitive); # same
36
37 NOTE: tie()d primitive must be tie()d before promote(). If it needs to be tie()d later, either re-promote() it or use tieable => 1 argument to promote() (see L</"promote() function">).
38
39 After that $primitive remains the same, but it is now bless()ed as object that exposes corresponding perltie methods, so that the following, for example, become interchangeable for B<both tied() and not tied()> %$primitive:
40
41 $primitive->{foo};
42 $primitive->FETCH('foo'); # same
43 $primitive->fetch('foo'); # same
44
45 Also, in case of tie()d primitive instead of:
46
47 tied(%$primitive)->method();
48
49 just be tied()less:
50
51 $primitive->method();
52
53 In case non-tied() primitives need to be interchangeable with tied() ones that have extended tied() interface, instead of cumbersome (possibly repeating many times) tied()-conditional access expression:
54
55 tied(%$primitive) ?
56 tied(%$primitive)->FETCH('foo', @args)
57 : $primitive->{foo};
58
59 just say:
60
61 $primitive->FETCH('foo', @args);
62
63 or faster:
64
65 $primitive->fast->FETCH('foo', @args);
66
67 However, for non-tie()d primitives the above tied()-conditional switch expression may still be significantly faster, so that it is still preferred for hot paths (tight loops, etc.). For speed and other trade-offs involved see L</"Performance"> and L</"fast()"> sections.
68
69 If $FH is a plain filehandle or tiehandle tied to class that implements stat(), ftest() (and others) and self() method, then the following simple code need not to discriminate between plain filehandle and tiehandle:
70
71 promote $FH;
72
73 $FH->stat();
74 $FH->ftest('-X');
75
76 # same in indirect method notation:
77 STAT $FH;
78 FTEST $FH '-X';
79
80 =head1 DESCRIPTION
81
82 Some applications need to accept both plain primitives as well as tie()d primitives with additional (non-perltie) methods and parameters supported by extended interface available through tied() object. For example, application cache may be allowed to optionally use either screamingly fast plain hash or some highly evolved persistent hashes tie()d to disk storage (like DB_File, etc.). There are many similar examples for filehandles, arrays and even scalars. Those are cases when Object::Hybrid combined with simple coding style can make code that handles those primitives compatible across whole spectrum, from plain primitives to all types of extended tied() primitives. There are also other uses, including working around gaps in tiehandle implementation, adding some fancy operations to primitives without using tie() as well as plain syntactic sugar.
83
84 In the context of this module hybrid object is defined as a Perl object that represents its own bless()ed primitive (i.e. the primitive it is implemented with, currently hash, scalar, array, or filehandle). According to this definition, hybrid object can be seen as both primitive and object at the same time. In general case, it is a violation of object encapsulation to access object's underlying bless()ed primitive directly (at least outside of class's methods), but in special case of hybrid objects it is perfectly ok to do so - no violation of encapsulation takes place.
85
86 Hybrid objects are instances of the class that is referred to as "hybrid class". This module implements default hybrid classes and exports promote() function that bless()es Perl's primitives (hash, scalar, array, or filehandle) into either default or user-specified (custom) hybrid classes to make them hybrid objects.
87
88 Promoting primitive to become hybrid (i.e. bless()ing it into hybrid class) simply adds object interface to primitive and is a way to extend Perl primitives that is compatible with and complementary to another major way of extending primitives - perltie API.
89
90 Specifically, benefits of promote()ing primitives are:
91
92 =over
93
94 =item Compatibility
95
96 Hybrid object has corresponding perltie methods interface for accessing underlying bless()ed primitive that object is implemented with (e.g. tiehash methods for accessing underlying bless()ed hash, etc.). Moreover, for hybrid object the following, for example, are equivalent and interchangeable for B<both tied() and not tied()> primitives:
97
98 $hybrid->{foo};
99 $hybrid->FETCH('foo'); # same
100 $hybrid->fetch('foo'); # same
101
102 Promoting primitives to become hybrids allows the same simple portable, non-specific code to manipulate (be compatible with) anything ranging from plain primitives to highly extended tie()d primitives as it unifies their interfaces and make them interchangeable.
103
104 For example, if same code is required to accept and handle both plain hashes, i.e. fast, in-memory hashes, and tie()d hashes with extended perltie interface, e.g. slow persistent hashes tie()d to disk storage, then it is useful to promote() each of those hashes to become hybrid. Whenever plain access is required the following code:
105
106 $hybrid->{foo};
107
108 will work for both in-memory and persistent hashes, and is really fast in case of in-memory hash. And in case you need to use extended interface, something like next code will also work for promote()d both in-memory and persistent hashes:
109
110 $hybrid->FETCH('foo', @args);
111
112 $hybrid->can('custom_method')
113 and $hybrid->custom_method();
114
115 For performance comparison of various interface options see L</"Performance"> section.
116
117 Despite promoting primitives to become hybrids turn them into Perl objects, compatibility with arbitrary Perl objects in practice has little value, since code that manipulates objects usually assume objects to be of very specific class.
118
119 =item tied()less access
120
121 Accessing tied() interface of tie()d primitive no longer requires cumbersome (possibly conditional) tied() call, i.e. instead of:
122
123 tied(%$hybrid)->method();
124
125 one can write:
126
127 $hybrid->method(); # same
128 $hybrid->fast->method(); # same, but may be faster
129
130 For performance comparison of various interface options see L</"Performance"> and L</"fast()"> sections.
131
132 =item Incomplete tie() implementation workaround
133
134 Currently tie()ing filehandles is still incomplete in Perl: sysopen(), truncate(), flock(), fcntl(), stat() and -X cannot currently be trapped. However, both tieclasses and hybrid classes can define corresponding methods or use self() method (see L</"Properties of hybrid objects">) to not distinguish between primitives for that matter:
135
136 promote $FH;
137
138 $FH->stat();
139 $FH->ftest('-X');
140
141 # same in indirect method notation:
142 STAT $FH;
143 FTEST $FH '-X';
144
145 # or sometimes self() method can be used for that end too:
146 stat $FH->self;
147 -X $FH->self;
148
149 =item Operator overloading
150
151 Custom hybrid classes can be used for overloading operators on primitives. However, unfortunately such hybrid classes currently can only be used to promote() non-tied() primitives (see L</"Operator overloading">).
152
153 =back
154
155 Object::Hybrid is a lightweight pure Perl module with no dependencies beyond core.
156
157 =head1 Stop reading now (or how to use this documentation)
158
159 Usually, there is no need to read any of the following documentation to use Object::Hybrid - you can stop reading at this point. What you have read so far, or even just self-explanatory SYNOPSIS, is enough in most cases. The following documentation covers optional features that need not to be learned for using Object::Hybrid in most usual case (e.g. occasionally).
160
161 =head1 C<use Object::Hybrid>
162
163 use Object::Hybrid; # exports nothing
164 use Object::Hybrid $feature; # enables single named feature
165 use Object::Hybrid \@feature; # enables array of named features
166 use Object::Hybrid \%options; # most general form
167 use Object::Hybrid %options; # most general form
168
169 The following features are supported:
170
171 use Object::Hybrid 'promote';
172 use Object::Hybrid feature => 'promote'; # same
173 use Object::Hybrid feature => ['promote']; # same
174 use Object::Hybrid export => 'promote'; # same
175 use Object::Hybrid export => ['promote']; # same
176
177 which exports (i.e. declares for use) the promote() function into caller's namespace.
178
179 Next features depend on autobox pragma being installed (can be installed from CPAN archive):
180
181 use Object::Hybrid 'autobox';
182 use Object::Hybrid feature => 'autobox'; # same
183 use Object::Hybrid feature => ['autobox']; # same
184 use Object::Hybrid autobox => Object::Hybrid->CLASS; # same, but can be custom hybrid class
185
186 which will automatically promote() any primitive within the current scope, and "unpromote" them back beyond that scope. It is is equivalent to:
187
188 use Object::Hybrid;
189 use autobox
190 HASH => Object::Hybrid->HASH_STATIC,
191 SCALAR => Object::Hybrid->SCALAR_STATIC,
192 ARRAY => Object::Hybrid->ARRAY_STATIC;
193
194 And closely related is:
195
196 use Object::Hybrid 'autopromote';
197 use Object::Hybrid feature => 'autopromote'; # same
198 use Object::Hybrid feature => ['autopromote']; # same
199 use Object::Hybrid autopromote => Object::Hybrid->CLASS; # same, but can be custom hybrid class
200
201 which makes any method call on non-blessed primitive in the lexical scope to automatically promote() that primitive.
202
203 =head1 promote() function
204
205 promote $primitive; # bless() $primitive to make it hybrid object
206 promote $primitive => \%args; # same, but with named arguments
207 promote $primitive => %args; # same
208 promote $primitive => $class; # same, but with explicit $class to tie() to or bless() into
209 promote $primitive => $class, \%args; # same, but with named arguments
210 promote $primitive => $class, %args; # same
211
212 The function promote() is an exportable constructor of hybrid objects.
213
214 In case $primitive is tied(), the tied() object is used as object interface of the hybrid (see L</"Delegation to tied() object">), unless custom hybrid $class is specified (see L</"Custom hybrid $class">).
215
216 In any case, promote() never (re)tie()s primitive, only bless()es it.
217
218 Exception is raised if $primitive specified is of type not currently supported by Object::Hybrid, no or not defined $primitive is specified.
219
220 The return value is $primitive itself bless()ed to become a hybrid object (return value may be useful if promote() is used in expressions).
221
222 The class that $primitive is bless()ed into is generated based on the type of primitive, whether it is tied(), custom $class and "mutable" option, if any are specified. User should not assume anything about resulting ref($primitive) class, except:
223
224 Object::Hybrid->Class->is(ref($primitive));
225 ref($primitive)->isa($class); # in case $class was specified
226
227 If promote() is called on a hybrid object, it gets re-bless()ed according to arguments provided. This may be useful for performance optimization in some cases, since performance depends on the way primitive is promote()d.
228
229 If promote() is called on non-hybrid object, the exception is raised, except when rebless => 1 option is provided. Later essentially is a "doorway" for converting objects into hybrids in rare case it may be needed (almost always a bad idea). (One such likely case is promote()ing some hybrid object incompatible with Object::Hybrid, e.g. IO::Object, using its class as custom hybrid class.)
230
231 The "tieable" boolean option specifies whether untied primitive can be tie()d after promote(). If primitive gets tie()d, its object interface immediately changes accordingly. However, for (much) better performance it is recommended to re-promote() such hybrid after tie()ing it instead of using tieable => 1 option (unless promote() cost is an issue).
232
233 The "mutable" boolean option commands whether the tied or tieable (tieable => 1) hybrid can be untie()d or re-tie()d after it has been tied. If tieable hybrid gets tie()d or untie()d, its object interface immediately changes accordingly. However, for (much) better performance it is recommended to re-promote() such hybrid after untie()ing or re-tie()ing it instead of using tieable => 1 option (unless promote() cost is an issue).
234
235 The "caller" boolean option commands whether the method calls on tied or tieable (tieable => 1) hybrid preserve caller(). This may need to be enabled in rare case that methods of unaware tied class (may) rely on caller(). By default, for hybrids that neither "mutable" (caller may not be preserved) nor "caller" (caller is always preserved) were set true upon promote(), the global $Object::Hybrid::CALLER = 1 can be used to preserve caller. In later case local($Object::Hybrid::CALLER) allows to exercise fine-granularity control over whether caller() is preserved for specific methods:
236
237 {
238 local $Object::Hybrid::CALLER = 1;
239 $hybrid->foo();
240 }
241
242 Note that use of either "mutable", "tieable" (in case of non-tied primitives), "caller" options or any combination of them may (some combinations - significantly) reduce performance of hybrid object interface.
243
244 The tie => $value option can be used to initialize tied() attribute of the hybrid object - see tied() attribute.
245
246 =head2 Custom hybrid $class
247
248 If custom hybrid $class is specified, then $primitive is bless()ed into hybrid class that inherits from $class.
249
250 If and only if $class overrides methods of the hybrid object, then L<properties of hybrid objects|/"Properties of hybrid objects"> become requirements for $class to comply with. Otherwise there are no requirements for the class, except it should make sense to use it as hybrid class, i.e. according to L<hybrid object definition|/DESCRIPTION> class should represent its bless()ed primitive (e.g. IO::Handle and subclasses may well be used as custom hybrid classes). In particular, calling promote() with the $class name of the empty class is equivalent to calling promote() without specifying custom $class, i.e. it will work. For lengthy discussion of hybrid class requirements refer to L<Object::Hybrid::Class>.
251
252 If custom $class is type-specific for given $primitive, the type-conditional expression for $class may need to be used by caller.
253
254 The alternative to using custom hybrid class is subclassing Object::Hybrid. Usually this way allows much more efficient implementations of hybrids, but it is more involved as as well.
255
256 =head1 Properties of hybrid objects
257
258 The following are the properties of hybrid objects:
259
260 =head2 Equivalent perltie API
261
262 Hybrid object exposes perltie interface (perltie methods) for its underlying bless()ed primitive B<and> that interface is equivalent to directly accessing underlying primitive - B<both> tie()d and not tie()d. This interface equivalence is what makes, say, next two lines to have exactly same effect for hash hybrids:
263
264 $hybrid->{foo};
265 $hybrid->FETCH('foo'); # same
266
267 For performance comparison of various interface options see L</"Performance"> section.
268
269 =head2 Complete perltie API
270
271 Currently tie()ing filehandles is still incomplete in Perl: sysopen(), truncate(), flock(), fcntl(), stat() and -X can't currently be trapped. However, hybrid object provides equivalent samename methods and their uppercase aliases (SYSOPEN(), TRUNCATE(), FLOCK(), FCNTL(), STAT() and FTEST()) to fill the gap and also allow compatibility with tiehandle classes that also implement them. This allows to write portable code that works around gaps in tiehandle implementation by B<always> using methods on hybrids filehandles instead of Perl built-in functions, for example:
272
273 promote $FH;
274
275 $FH->stat();
276 $FH->ftest('-X');
277
278 # same with indirect method calls...
279 STAT $FH;
280 FTEST $FH '-X';
281
282 Thus, to avoid problems with gaps in tiehandle implementation simply always call samename methods on hybrids instead of corresponding built-in functions.
283
284 =head2 Delegation to tied() object
285
286 In case of tied() primitives, hybrid object tries to delegate all method calls to tied() object. Delegation invokes called method on tied() object instead of hybrid. This allows invoking perltie methods B<with parameters> on hybrid directly (instead of on tied() object):
287
288 $hybrid->STORE($value, @args);
289
290 Delegation exposes entire interface of tied() object as hybrid object interface. Caller may use $hybrid->can('foo') to determine whether tied() object (if any) or hybrid implement certain methods.
291
292 If tied() object provides no called method, delegation fails and then hybrid object falls back to calling its own samename method (called "fallback method") on hybrid itself. Fallback methods are simply same methods that would be called if hybrid is not tied(). This means methods of the non-tied() hybrid remain available if hybrid is tied(), unless tied() object exposes its own samename methods.
293
294 In other words, tie()d hybrid may expose methods that tied() object do not provide. For example, since stat() is not a perltie method currently, it is unlikely to be implemented by tiehandle class, but it is provided by hybrid object to have portable C<< promote($tied_fh)->stat() >> workarounds for currently broken C<stat($tied_fh)>.
295
296 Note that delegation for standard perltie methods almost always works (no fallback), because normally tieclass does implement perltie methods.
297
298 =head2 Method aliases
299
300 The promote()ing of primitive to become hybrid object provides altered-case aliases for all its methods (including lowercase aliases for all perltie methods).
301
302 This feature is especially relevant in case when there are samename built-in functions for accessing primitives: shift(), exists(), seek(), etc. In this case and as general coding style for hybrids: the lower case should be used as functions or in direct method calls notation, while upper case can be used for indirect method call notation (later minimizes chances of indirect method notation colliding with non-parenthesized same name function calls with single scalar argument, like C<foo $FH>). For example:
303
304 seek $FH, 0, 0; # function call (coma after $FH, no extra arguments)
305 SEEK $FH 0, 0, @args; # indirect method call (no coma after $FH, @args extended interface)
306 $FH->seek(0, 0, @args); # direct method call (@args extended interface)
307
308 In case of tie()d hybrid it is more efficient to call method that is defined by underlying tied() class, for example, FETCH() is likely to be faster than fetch() for tie()d primitives (as their tied() classes usually define no fetch(), just FETCH()). In all other cases aliases are equally efficient.
309
310 Setting C<local $Object::Hybrid::Portable = 1> (local()ized to some scope) changes behavior of aliases making them non-equivalent. Calls of lower-case aliases now do not fail (are "fail-safe") due to method being not defined by either hybrid class or underlying tied() class (if any), becoming no-op and returning empty list or undef scalar. This allows to write portable code that calls non-standard methods on tied() hybrids without (ab)using can() calls or eval{} wraps, which otherwise would make code cumbersome (e.g. in case of eval{} it is necessary to manually distinguish "can't find method" from errors in defined method, etc.). But it is of course risky too, as typos will not blow up, leading to silent error propagation, so that $Object::Hybrid::Portable = 1 is an optional feature that should be used with care, after first testing code without it.
311
312 In contrast, upper-case aliases are not similarly fail-safe under C<local $Object::Hybrid::Portable = 1>, calling them is a fatal error if method, both lower-case and upper-case, is not defined, so that they can be used to ensure method is really called (mnemonics: insist on it being called by writing it in upper case). If, however, lower-case method is defined, the upper-case call will call it, not fail. For example:
313
314 {
315 local $Object::Hybrid::Portable = 1;
316
317 $hybrid->non_existing_method(); # will not fail due to "can't find method"
318 $hybrid->NON_EXISTING_METHOD(); # fatal "can't find method" error
319
320 $hybrid->maybe_existing_method(); # will not fail due to "can't find method"
321 $hybrid->MAYBE_EXISTING_METHOD(); # may be a fatal "can't find method" error
322
323 $filehandle_hybrid->fetch(); # will not fail due to "can't find method"
324 $filehandle_hybrid->FETCH(); # likely fatal "can't find method" error (since filehandles normally have no FETCH()), but will call fetch() (not fail) if fetch() happens to be defined
325 }
326
327 =head2 call()
328
329 $hybrid->call(method => @args);
330
331 is the short form of:
332
333 {
334 local $Object::Hybrid::Portable = 1;
335 $hybrid->method(@args);
336 }
337
338 Except in case of call() &$method sees real caller one level deeper in the stack (which may be unexpected by methods that use caller()) and character case of method()'s name is irrelevant.
339
340 =head2 fast()
341
342 The fast() efficiently returns tied() object for tie()d invocant, and invocant itself for non-tied. The fast() method is used for "manual" delegation to tied() object as a way of performance optimization:
343
344 $hybrid->fast->FETCH('a'); # for tied() $hybrid is much faster than...
345 $hybrid->FETCH('a');
346
347 $hybrid->fast->can('foo'); # for tied() $hybrid is much faster than...
348 $hybrid->can('foo');
349
350 For non-tied hybrids, however, situation is reversed, but in absolute terms using fast() often pays off, especially where tied hybrids are more common throughput. The trade-off however is that $hybrid->fast->FETCH() syntax provides no method aliases, no fail-safety for non-defined methods in case of true $Object::Hybrid::Portable, and raises exception instead of falling back to calling samename hybrid's method in case tied() class defines no called method, so that using it is more risky and requires better knowledge of tied() classes involved.
351
352 =head2 self() method
353
354 The self() method returns underlying primitive: either bless()ed primitive of the hybrid object (i.e. hybrid object itself) or, if possible, real underlying primitive that is used by tied() object/class.
355
356 Many tied() objects (like Tie::ExtraHash) transparently delegate operations on tie()d primitive to real primitive encapsulated somewhere inside that tied() object, using that object just to store some additional state. If this is the case, tied() class may define self() as accessor for that underlying primitive to directly expose it to methods of the hybrid class and to users. The self() method allows to access that real primitive directly, falling back to hybrid's bless() primitive, if it is not possible or tied() class do not provide self() method. As a result, methods of custom hybrid class can have access to both tie()d bless()ed primitive (slow) and underlying real primitive (fast).
357
358 The tied() class must not define self() if this may result in violation of encapsulation, i.e. if delegation to underlying real primitive is not transparent enough. Example of transparent tieclass that may define self() is Tie::ExtraHash. On the other hand some tieclasses, like Tie::StdHash, are so transparent that need not to define self() at all as default one is good for them.
359
360 The self() method can have a number of useful applications, in particular to work around gaps in tiehandle implementation and to increase performance, as it allows hybrid methods to quickly bypass perltie layer and operate on underlying primitive directly, which may bring significant efficiency benefits, especially for some bulk operations.
361
362 For example, since there is no yet perltie support for stat(), -X tests called on tiehandle do not propagate to underlying real filehandle, so they should be somehow propagated manually, but it requires knowing how to get underlying filehandle, if there is any, out of tied() object. Defining self() method in tieclass is supposed to do just that, and hybrid classes are expected to define self() method as well, so that portable code (assuming tied() classes define self()) can simply be:
363
364 promote $FH;
365
366 stat $FH->self;
367 -X $FH->self;
368
369 # or nearly same using methods (default implementations of these methods also use self() under the hood):
370 STAT $FH;
371 FTEST $FH '-X';
372 $FH->stat();
373 $FH->ftest('-X');
374
375 If tieclass defines self(), the sysopen(), truncate(), flock(), fcntl(), stat() and ftest() methods of corresponding tie()d hybrid object will operate correctly without tieclass implementing them.
376
377 The Hybrid::Object makes use of self() only if it is defined by tieclass of tie()d primitive, so that hybrids do not depend on tieclass implementing self() method.
378
379 =head2 tied() method
380
381 Returns what built-in tied() would return called on hybrid. The only difference is that it is a method and reference type of the hybrid need not to be known.
382
383 =head2 Optional bless() method
384
385 If custom hybrid class defines bless() method, the C<< $hybrid_class->bless($primitive) >> is called instead of otherwise calling C<bless($primitive, $hybrid_class)>. The bless() method is optional. It can be used as constructor/initializer for hybrid object, except it is to reuse $primitive (same as built-in bless()) instead of creating new.
386
387 =head2 C<< Object::Hybrid->Class >>
388
389 Hybrid objects can be recognized with the following test:
390
391 Object::Hybrid->Class->is($hybrid);
392
393 =head1 new() method
394
395 $hybrid = new Object::Hybrid $primitive; # bless() to make $primitive a hybrid
396 $hybrid = new Object::Hybrid $primitive => \%args; # same, but with named arguments
397 $hybrid = new Object::Hybrid $primitive => %args; # same
398 $hybrid = new Object::Hybrid $primitive => $class; # same, but with explicit $class to tie() to or bless() into
399 $hybrid = new Object::Hybrid $primitive => $class, \%args; # same, but with named arguments
400 $hybrid = new Object::Hybrid $primitive => $class, %args; # same
401
402 Or corresponding direct method call notation for any of the above can be used, for example:
403
404 $hybrid = Object::Hybrid->new($primitive); # etc.
405
406 The new() constructor promote()s $primitive to hybrid and returns it. It is roughly equivalent to:
407
408 sub new { shift; return promote(@_) }
409
410 Refer to promote() documentation.
411
412 Note that new() do not construct object of Object::Hybrid class, even not $hybrid->isa('Object::Hybrid'), so beware.
413
414 =head1 tie() method
415
416 $tied = Object::Hybrid->tie( $primitive, $tieclass, @args); # for %$primitive same as...
417 $tied = tie(%$primitive, $tieclass, @args); # ... except $primitive also gets promote()d to hybrid
418
419 =head1 Class() method
420
421 Object::Hybrid relies on Class::Tag to store and query inheritable meta-data of hybrid classes, and uses Object::Hybrid::Class as tagger class in Class::Tag's terms. The Class() method always returns the name of that tagger class. This is primarily for convenience of using it in expressions. Refer to L<Object::Hybrid::Class> for currently supported tags and their semantics.
422
423 package Foo;
424 use Object::Hybrid::Class; # tags Foo as standalone hybrid class
425
426 Object::Hybrid->Class eq 'Object::Hybrid::Class'; # true
427 Object::Hybrid->Class->is('Foo'); # true
428 Object::Hybrid->Class->is('Bar'); # false
429
430 =head1 is() method
431
432 The is () is an equivalent of Object::Hybrid->Class->is():
433
434 promote $hybrid;
435 Object::Hybrid->is( $hybrid); # true
436 Object::Hybrid->Class->is( $hybrid); # same
437 Object::Hybrid->is( $not_hybrid); # false
438 Object::Hybrid->Class->is($not_hybrid); # same
439
440 =head1 ref_*() methods
441
442 These are utility methods useful to sort things out. Generally, all ref_foo() (ref_*()) methods return boolean that tells whether its argument is reference or not, but exact boolean value depends of the value of 'foo' suffix:
443
444 =head2 ref_type() method
445
446 Object::Hybrid->ref_type({}) eq 'HASH'; # true
447 Object::Hybrid->ref_type(bless {}, 'Foo') eq 'HASH'; # true
448
449 and so on...
450
451 =head2 ref_isa() method
452
453 $obj = bless {}, 'Foo';
454 Object::Hybrid->ref_isa($obj); # true
455 Object::Hybrid->ref_isa($obj) eq $obj; # true
456 Object::Hybrid->ref_isa($obj, 'Foo') eq $obj; # true
457 Object::Hybrid->ref_isa($obj, 'Bar'); # false
458 Object::Hybrid->ref_isa({}); # false
459
460 and so on...
461
462 This method is useful to try some unknown $thing at hands that it is too uncertain to call $thing->isa('Foo') on it. It returns true, more specifically passes through its argument (for use in expressions and chained calls) if reference is blessed and, if second argument defined, isa() of second argument type (exact type can be obtained with ref(ref_isa($var)) instead). Otherwise returns false. More specifically, returns 0 for blessed references, '' for non-blessed references and undef for non-references.
463
464 =head2 ref_tied() method
465
466 $tied = tie %$primitive, 'Foo';
467 Object::Hybrid->ref_tied($primitive) eq $tied; # true
468 Object::Hybrid->ref_tied({}) eq '0'; # true
469 Object::Hybrid->ref_tied(sub{}) eq ''; # true, since sub{} is not tie()able
470 Object::Hybrid->ref_tied('string') eq ''; # true, since 'string' is not tie()able
471
472 and so on.
473
474 =head1 Perltie classes
475
476 Hybrid objects are out of the box compatible with any valid tieclass.
477
478 However, to support workarounds for "gaps" in perltie implementation, tieclasses may need to meet additional requirements - those are some of requirements that hybrid classes already comply with, intended specifically to work around perltie implementation gaps, namely: L</"Complete perltie API"> and L</"self() method">. Currently tie()ing filehandles is still incomplete in Perl, so these requirements mainly apply to tiehandle classes. The most simple tiehandle classes, like Tie::StdHandle (loaded by "use Tie::Handle"), already comply with this requirements, as for them default self() and other methods provided by default hybrid class are good enough. A bit more complex tiehandle classes need just to implement self() method. If defining self() is not possible in case of more complex tiehandle classes, additional SYSOPEN(), TRUNCATE(), FLOCK(), FCNTL(), STAT() and FTEST() methods may need to be implemented as workarounds by tiehandle class.
479
480 Since tie() do not pass primitive to be tie()d to TIE*() constructor, TIE*() cannot be made to optionally promote() that primitive. Instead, tieclass can expose promote() as one of its methods allowing user to promote primitives or expose Object::Hybrid->tie() method analog for built-in tie() that both tie()s and promote() given primitive. This, however, should probably not be dove via subclassing.
481
482 =head1 Operator overloading
483
484 Custom hybrid classes can be used for overloading operators on promote()d primitives. However, unfortunately hybrid classes with overloaded operators currently can only be used to promote() non-tied() primitives. This is because currently overload pragma is broken - bless()ing tie()d primitive into such class will implicitly untie() it. Should this be fixed in the future, operator overloading can be used without this limitation.
485
486 However, even used on non-tied() primitives operator overloading is very powerful and can have some interesting (and possibly even useful) applications. In particular, overloading of dereference operators allows to achieve effects somewhat similar to using tie(), like "back-door" state similar to that of tied() objects. It is even possible to have "hybrid primitive" that is simultaneously hash, scalar, array, subroutine and glob (however such hybrid class may violate equivalence requirement as FETCH(0) need to be equivalent to $hybrid->{0} and $hybrid->[0] at the same time).
487
488 =head1 Performance
489
490 The performance preferences for hash hybrids are (in order from fastest to slowest, all figures are quoted for CPU-constrained virtual server, so only their comparison with each other matters):
491
492 $non_blessed->{foo} # ~ 1_700_000/s
493 $nontied_hybrid->{foo}; # ~ 1_700_000/s
494 $nontied_hybrid->FETCH('foo'); # ~ 300_000/s
495 tied(%$tied_hybrid)->FETCH('foo'); # ~ 230_000/s
496 $nontied_hybrid->fast->FETCH('foo'); # ~ 200_000/s (slower despite fast())
497 $tied_hybrid->fast->FETCH('foo'); # ~ 150_000/s
498 $tied_hybrid->FETCH('foo'); # ~ 80_000/s
499 $tied_hybrid->{foo}; # ~ 60_000/s
500
501 For comparison, the promote() performance (all including DESTROY() cost):
502
503 bless $primitive => $hybrid_class # ~ 80_000/s (this is fast analog of promote())
504 promote($primitive) # ~ 35_000/s
505 promote($primitive => $class) # ~ 21_000/s
506
507 These results are produced by bench/benchmark_hash.pl script available in the Object::Hybrid distribution, and assume default hybrid classes. Figures for promote($primitive => $class) realistically assume same $class value is used in benchmarked calls (otherwise it will be significantly slower), and also include DESTROY() costs. For fast promote()ing of same type of primitives, simply bless() to proper hybrid class:
508
509 my $hybrid_class = ref promote({});
510 bless {}, $hybrid_class foreach (1..1000000);
511
512 Above results suggests that tied()-conditional access switching expression is (currently) the fastest solution that is to be used in hot paths (tight loops, etc.) and it requires no promote()ing:
513
514 tied(%$primitive) ?
515 tied(%$primitive)->FETCH('foo') # ~230_000/s
516 : $primitive->{foo}; # ~1_700_000/s
517
518 However, using this construct repeatedly may be too cumbersome, so out of hot paths (tight loops, etc.) promote()ing to hybrid can be used to simplify code while retaining and enhancing its portability across various tie()d and non-tie()d primitives.
519
520 For hybrid interfaces performance varies widely depending on whether it is a tied or non-tied respectively:
521
522 $hybrid->{foo}; # ~ 60_000 - 1_700_000/s
523 $hybrid->FETCH('foo'); # ~ 80_000 - 300_000/s
524 $hybrid->fast->FETCH('foo'); # ~ 150_000 - 200_000/s
525
526 Consequently, use of any of these should be decided based on the projected use mix of tied vs. non-tied primitives.
527
528 =head1 TODO
529
530 Currently tests cover only tiehashes and tiehandles, there should be tests for other types as well.
531
532 As soon as (and if) Object::Hybrid interface stabilizes enough, its version is to jump to 1.0.
533
534 =head1 SEE ALSO
535
536 The C<use autobox> pragma is another way of doing somewhat similar, but not the same things, so autobox and Object::Hybrid are not mutually substitutive. However, if C<autobox> pragma is installed, then either "autobox" or "autopromote" feature can be enabled - see L</"use Object::Hybrid">.
537
538 Objects of standard IO::Handle class and its subclasses (such as IO::File or IO::Socket) are hybrid objects according to general hybrid object definition used by Object::Hybrid, but they are incompatible with promote()d hybrids. However, it should be possible to promote() IO::Handle object to become compatible hybrid.
539
540 =head1 SUPPORT
541
542 Send bug reports, patches, ideas, suggestions, feature requests or any module-related information to L<mailto:parsels@mail.ru>. They are welcome and each carefully considered.
543
544 In particular, if you find certain portions of this documentation either unclear, complicated or incomplete, please let me know, so that I can try to make it better.
545
546 If you have examples of a neat usage of Object::Hybrid, drop a line too.
547
548 =head1 AUTHOR
549
550 Alexandr Kononoff (L<mailto:parsels@mail.ru>)
551
552 =head1 COPYRIGHT AND LICENSE
553
554 Copyright (c) 2010 Alexandr Kononoff (L<mailto:parsels@mail.ru>). All rights reserved.
555
556 This program is free software; you can use, redistribute and/or modify it either under the same terms as Perl itself or, at your discretion, under following Simplified (2-clause) BSD License terms:
557
558 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
559
560 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
561 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
562
563 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
564
565 =cut
566
567 1 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
568
569 1 ▶use Scalar::Util qw(reftype refaddr weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
570
571 1 ▶use Object::Hybrid::Class (); # Object::Hybrid itself is not a hybrid class
Subroutine BEGIN: called CC=1 SCAR=0.0
572
573 sub HASH_UNTIED () { 'Object::Hybrid::HASH' }
574 sub HASH_STATIC () { 'Object::Hybrid::HASH_STATIC' }
575 sub HASH_STATIC_CALLER () { 'Object::Hybrid::HASH_STATIC_CALLER' }
576 sub HASH_MUTABLE () { 'Object::Hybrid::HASH_MUTABLE' }
577 sub HASH_MUTABLE_CALLER () { 'Object::Hybrid::HASH_MUTABLE_CALLER' }
578
579 sub SCALAR_UNTIED () { 'Object::Hybrid::SCALAR' }
580 sub SCALAR_STATIC () { 'Object::Hybrid::SCALAR_STATIC' }
581 sub SCALAR_STATIC_CALLER () { 'Object::Hybrid::SCALAR_STATIC_CALLER' }
582 sub SCALAR_MUTABLE () { 'Object::Hybrid::SCALAR_MUTABLE' }
583 sub SCALAR_MUTABLE_CALLER () { 'Object::Hybrid::SCALAR_MUTABLE_CALLER' }
584
585 sub ARRAY_UNTIED () { 'Object::Hybrid::ARRAY' }
586 sub ARRAY_STATIC () { 'Object::Hybrid::ARRAY_STATIC' }
587 sub ARRAY_STATIC_CALLER () { 'Object::Hybrid::ARRAY_STATIC_CALLER' }
588 sub ARRAY_MUTABLE () { 'Object::Hybrid::ARRAY_MUTABLE' }
589 sub ARRAY_MUTABLE_CALLER () { 'Object::Hybrid::ARRAY_MUTABLE_CALLER' }
590
591 sub GLOB_UNTIED () { 'Object::Hybrid::GLOB' }
592 sub GLOB_STATIC () { 'Object::Hybrid::GLOB_STATIC' }
593 sub GLOB_STATIC_CALLER () { 'Object::Hybrid::GLOB_STATIC_CALLER' }
594 sub GLOB_MUTABLE () { 'Object::Hybrid::GLOB_MUTABLE' }
595 sub GLOB_MUTABLE_CALLER () { 'Object::Hybrid::GLOB_MUTABLE_CALLER' }
596
597 sub CLASS_AUTOPROMO () { 'Object::Hybrid::AUTOPROMOTE' }
598 sub FRONTAL () { 'FRONTAL' }
599 sub Class () { 'Object::Hybrid::Class' }
600 sub CLASS_DEFAULT () { undef }
601
602 15 ▶sub frontclass_name {
Subroutine frontclass_name: called CC=3 SCAR=13.1
Pod undocumented
603 15 my (undef, $class, $primitive) = @_;
604 15 ▶ return join '_', $class, ref $primitive ? reftype($primitive) : $primitive||(), FRONTAL
Branch: 1 branch
BranchTrueFalseTotal
ref $primitive ? : 0 15 15
Condition33%1/3
$primitive or ()
l!l&&r!l&&!r
1500
MC/DC0%0/2
$primitive or ()
$primitive ()
Truth table33%1/3
A or B
A= $primitiveB= ()
ABresult
1X1
011
000
605 }
606
607 1 my %class4type = (
608 HASH => HASH_STATIC,
609 ARRAY => ARRAY_STATIC,
610 SCALAR => SCALAR_STATIC,
611 GLOB => GLOB_STATIC,
612 );
613
614 1 my %untied_class4type = (
615 HASH => HASH_UNTIED,
616 ARRAY => ARRAY_UNTIED,
617 SCALAR => SCALAR_UNTIED,
618 GLOB => GLOB_UNTIED,
619 );
620
621 0 ▶sub class4type {
Subroutine class4type: not called CC=2 SCAR=17.9
Pod undocumented
622 0 my $self = shift;
623 0 my $accessor = $self->name4type(@_);
624 0 ▶ return $self->$accessor||()
Condition0%0/3
$self->$accessor || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->$accessor || ()
$self->$accessor ()
Truth table0%0/3
A || B
A= $self->$accessorB= ()
ABresult
1X1
011
000
625 }
626
627 15 ▶sub name4type { # the only required parameter is 'reftype' - can be ref() or reference of corresponding type
Subroutine name4type: called CC=7 SCAR=20.4
Pod undocumented
628 15 my ($self, $type);
629 15 ($self, %$type) = @_;
630
631 push my @accessor
632 , ref $type->{reftype}
633 ? reftype $type->{reftype}
634 : $type->{reftype}
635 if $type->{reftype}
636 15 ▶ or croak("No 'reftype' parameter specified");
Branch: 2 branches
BranchTrueFalseTotal
if $type->{"reftype"} or croak("No 'reftype' parameter specified") 15 0 15
ref $type->{'reftype'} ? : 0 15 15
Condition50%1/2
$type->{"reftype"} or croak("No 'reftype' parameter specified")
l!l
150
MC/DC0%0/1
$type->{"reftype"} or croak("No 'reftype' parameter specified")
$type->{"reftype"}
Truth table50%1/2
A
A= $type->{"reftype"}
Aresult
11
00
637
638 15 ▶ if (!$type->{tieable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $type->{'tieable'}) { } 7 8 15
639 7 push @accessor, 'UNTIED';
640 }
641 else {
642 8 ▶ push @accessor, $type->{mutable} ? 'MUTABLE' : 'STATIC';
Branch: 1 branch
BranchTrueFalseTotal
$type->{'mutable'} ? : 0 8 8
643 push @accessor, 'CALLER'
644 8 ▶ if $type->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $type->{"caller"} 0 8 8
645 }
646
647 15 my $accessor = join '_', @accessor;
648
649 15 return $accessor
650 }
651
652 1 __PACKAGE__->import(qw(promote));
653 2 ▶sub import {
Subroutine import: called CC=29 SCAR=53.1
654 2 my $self = shift;
655
656 # interface...
657 2 ▶ my $opt
Branch: 4 branches
BranchTrueFalseTotal
@_ > 1 ? : 0 2 2
!@_ ? : 0 2 2
ref $_[0] eq 'HASH' ? : 0 2 2
ref $_[0] eq 'ARRAY' ? : 0 2 2
658 = @_ > 1 ? {@_}
659 : !@_ ? { }
660 : ref $_[0] eq 'HASH' ? $_[0]
661 : ref $_[0] eq 'ARRAY' ? { feature => [$_[0]] }
662 : { feature => [$_[0]] };
663
664 # normalize %$opt...
665 2 foreach my $list (qw(feature export autopromote)) {
666 next
667 6 ▶ if !exists $opt->{$list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{$list} 4 2 6
668 ref $opt->{$list} eq 'ARRAY'
669 or $opt->{$list}
670 2 ▶ = [$opt->{$list}];
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{$list} eq "ARRAY" or $opt->{$list} = [$opt->{$list}] 2 0 2
671 }
672
673 2 my @goto;
674
675 # process features first...
676 2 ▶ foreach my $feature (ref $opt->{feature} eq 'ARRAY' ? @{$opt->{feature}} : $opt->{feature}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'feature'} eq 'ARRAY' ? : 2 0 2
677 2 ▶ if ($feature eq 'promote') { push @{$opt->{export}}, $feature }
Branch: 1 branch
BranchTrueFalseTotal
if ($feature eq "promote") 2 0 2
678
679 # mutually exclusive features...
680 2 ▶ if ($feature eq 'autobox') {
Branch: 3 branches
BranchTrueFalseTotal
if ($feature eq 'autobox') { } 0 2 2
elsif ($feature eq 'autopromote') { } 0 2 2
elsif ($feature eq 'SAFE') { } 0 2 2
681 #load_type($self->CLASS);
682 0 $self->load_type('HASH_STATIC');
683 0 $self->load_type('SCALAR_STATIC');
684 0 $self->load_type('ARRAY_STATIC');
685
686 require
687 0 autobox;
688 autobox::import( ref($self)||$self,
689 HASH => $opt->{$feature}||$self->HASH_STATIC, # method instead of constant, for subclassing...
690 SCALAR => $opt->{$feature}||$self->SCALAR_STATIC,
691 #GLOB => $opt->{$feature}||$self->GLOB_STATIC, # not supported by autobox
692 0 ▶ ARRAY => $opt->{$feature}||$self->ARRAY_STATIC, );
Condition0%0/12
ref $self || $self
l!l&&r!l&&!r
000
$opt->{$feature} || $self->HASH_STATIC
l!l&&r!l&&!r
000
$opt->{$feature} || $self->SCALAR_STATIC
l!l&&r!l&&!r
000
$opt->{$feature} || $self->ARRAY_STATIC
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
MC/DC0%0/2
$opt->{$feature} || $self->HASH_STATIC
$opt->{$feature} $self->HASH_STATIC
MC/DC0%0/2
$opt->{$feature} || $self->SCALAR_STATIC
$opt->{$feature} $self->SCALAR_STATIC
MC/DC0%0/2
$opt->{$feature} || $self->ARRAY_STATIC
$opt->{$feature} $self->ARRAY_STATIC
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $opt->{$feature}B= $self->HASH_STATIC
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $opt->{$feature}B= $self->SCALAR_STATIC
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $opt->{$feature}B= $self->ARRAY_STATIC
ABresult
1X1
011
000
693 }
694 elsif ($feature eq 'autopromote') {
695 require
696 0 autobox;
697 0 ▶ autobox::import( ref($self)||$self,
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
698 HASH => CLASS_AUTOPROMO,
699 SCALAR => CLASS_AUTOPROMO,
700 #GLOB => CLASS_AUTOPROMO, # not supported by autobox
701 ARRAY => CLASS_AUTOPROMO, );
702 0 my $autoload
703 = __PACKAGE__ . '::AUTOLOAD';
704 0 ▶ *{ CLASS_AUTOPROMO . '::AUTOLOAD' } = sub{
Subroutine __ANON__: not called CC=3 SCAR=24.8
705 0 ▶ $self->new($_[0], @{$opt->{$feature}}||());
Condition0%0/3
@{$opt->{$feature};} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$opt->{$feature};} || ()
@{$opt->{$feature};} ()
Truth table0%0/3
A || B
A= @{$opt->{$feature};}B= ()
ABresult
1X1
011
000
706 0 $$autoload =~ s/^.*:://;
707 0 ▶ goto &{ $_[0]->can($$autoload)
Condition0%0/2
$_[0]->can($$autoload) || croak(_cant_locate_object_method($_[0], $$autoload))
l!l
00
MC/DC0%0/1
$_[0]->can($$autoload) || croak(_cant_locate_object_method($_[0], $$autoload))
$_[0]->can($$autoload)
Truth table0%0/2
A
A= $_[0]->can($$autoload)
Aresult
11
00
708 or croak(_cant_locate_object_method($_[0], $$autoload)) };
709 0 };
710 }
711 0 elsif ($feature eq 'SAFE') { $opt->{$feature} = 1; }
712 }
713
714 # process options...
715 2 ▶ if ($opt->{export}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"export"}) 2 0 2
716 2 my @symbols;
717 2 ▶ foreach my $symbol (@{$opt->{export}||[]}) {
Condition50%1/2
$opt->{'export'} || []
l!l
20
MC/DC0%0/1
$opt->{'export'} || []
$opt->{'export'}
Truth table50%1/2
A
A= $opt->{'export'}
Aresult
11
00
718 2 ▶ if ( $symbol eq 'promote' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol eq 'promote') { } 2 0 2
719 2 my $promote = $self->can(qw(new));
720 2 *{join '::', scalar caller, $symbol}
721 #= sub{ unshift @_, $self; goto &$promote };
722 2 ▶ = sub{ $self->$promote(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
723 }
724 0 else { push @symbols, $symbol }
725 }
726
727 2 ▶ if (@symbols
Branch: 1 branch
BranchTrueFalseTotal
if (@symbols or @{(ref $self || $self) . '::EXPORT';} or @{"Object::Hybrid::EXPORT";}) 0 2 2
Condition33%2/6
@symbols or @{(ref $self || $self) . '::EXPORT';} or @{"Object::Hybrid::EXPORT";}
l!l&&r!l&&!r
002
@symbols or @{(ref $self || $self) . '::EXPORT';}
l!l&&r!l&&!r
002
MC/DC0%0/3
@symbols or @{(ref $self || $self) . '::EXPORT';} or @{"Object::Hybrid::EXPORT";}
@symbols @{(ref $self || $self) . '::EXPORT';} @{"Object::Hybrid::EXPORT";}
Truth table25%1/4
A or B or C
A= @symbolsB= @{(ref $self || $self) . '::EXPORT';}C= @{"Object::Hybrid::EXPORT";}
ABCresult
1XX1
01X1
0011
0000
728 2 ▶ or @{(ref($self)||$self).'::EXPORT'}
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
729 2 or @{ __PACKAGE__.'::EXPORT'}) {
730 require
731 0 Exporter;
732 0 ▶ Exporter::export_to_level(1, $self, @symbols) or
Branch: 1 branch
BranchTrueFalseTotal
Exporter::export_to_level(1, $self, @symbols) or Exporter::export_to_level(1, __PACKAGE__, @symbols) 0 0 0
733 Exporter::export_to_level(1, __PACKAGE__, @symbols); # "inheritance" of export, subclasses can define their own @EXPORTs,
734 }
735 }
736
737 2 ▶ if (@goto) {
Branch: 1 branch
BranchTrueFalseTotal
if (@goto) 0 2 2
738 0 @_ = @goto;
739 0 goto &{shift(@_)};
740 }
741 }
742
743 54 ▶sub is { Object::Hybrid::Class->is($_[1]) }
Subroutine is: called CC=1 SCAR=0.0
Pod undocumented
744
745 1 my %PromoclassCache;
746 my %PromoclassCache2;
747 1 my %PromoclassCache3;
748 1 my %HybridClass;
749 1 my %DefaultClass;
750
751 1 *promote = \&new; # method, not function
752 113 ▶sub new {
Subroutine new: called CC=36 SCAR=38.3
Pod undocumented
753 113 ▶ my $primitive_is_tied = (
Branch: 1 branch
BranchTrueFalseTotal
(my $primitive_tied = _ref_tied($_[1])) ? : 82 31 113
754 my $primitive_tied = _ref_tied($_[1]) ) ? 1 : 0;
755
756 113 { return bless $_[1]
757 113 ▶ , $PromoclassCache2{ref $_[1]}->[$primitive_is_tied]||next
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 47 66 113
Condition100%2/2
$PromoclassCache2{ref $_[1]}[$primitive_is_tied] || (next)
l!l
641
MC/DC100%1/1
$PromoclassCache2{ref $_[1]}[$primitive_is_tied] || (next)
$PromoclassCache2{ref $_[1]}[$primitive_is_tied]
Truth table100%2/2
A
A= $PromoclassCache2{ref $_[1]}[$primitive_is_tied]
Aresult
11
00
758 if @_ == 2; } # fast shortcircuit
759
760 107 ▶ @_>1 or croak("Error: Nothing to promote");
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 or croak("Error: Nothing to promote") 107 0 107
761
762 107 my $self = shift;
763 107 my $primitive = $_[0];
764
765 107 my ($class, $args);
766 ( undef
767 107 ▶ , ref $_[1] eq 'HASH' ? ( $args)
Branch: 3 branches
BranchTrueFalseTotal
ref $_[1] eq 'HASH' ? : 0 107 107
ref $_[2] eq 'HASH' ? : 0 107 107
@_ % 2 ? : 77 30 107
768 : ref $_[2] eq 'HASH' ? ($class, $args)
769 : @_ % 2 ? %$args
770 : ($class, %$args) ) = @_;
771
772 107 ▶ $class ||= ($DefaultClass{ref($self)||$self} ||= $self->CLASS_DEFAULT);
Condition44%4/9
$class ||= ($DefaultClass{ref $self or $self} ||= $self->CLASS_DEFAULT)
l!l&&r!l&&!r
30077
$DefaultClass{ref $self or $self} ||= $self->CLASS_DEFAULT
l!l&&r!l&&!r
0077
ref $self || $self
l!l&&r!l&&!r
0770
MC/DC50%1/2
$class ||= ($DefaultClass{ref $self or $self} ||= $self->CLASS_DEFAULT)
$class ($DefaultClass{ref $self or $self} ||= $self->CLASS_DEFAULT)
MC/DC0%0/2
$DefaultClass{ref $self or $self} ||= $self->CLASS_DEFAULT
$DefaultClass{ref $self or $self} $self->CLASS_DEFAULT
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A ||= B
A= $classB= ($DefaultClass{ref $self or $self} ||= $self->CLASS_DEFAULT)
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $DefaultClass{ref $self or $self}B= $self->CLASS_DEFAULT
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
773
774 107 { return bless $primitive
775 107 ▶ , $PromoclassCache3{ref $primitive}->{$class}[$primitive_is_tied]||next
Branch: 1 branch
BranchTrueFalseTotal
unless %$args 71 36 107
Condition100%2/2
$PromoclassCache3{ref $primitive}{$class}[$primitive_is_tied] || (next)
l!l
665
MC/DC100%1/1
$PromoclassCache3{ref $primitive}{$class}[$primitive_is_tied] || (next)
$PromoclassCache3{ref $primitive}{$class}[$primitive_is_tied]
Truth table100%2/2
A
A= $PromoclassCache3{ref $primitive}{$class}[$primitive_is_tied]
Aresult
11
00
776 if !%$args; } # slower shortcircuit
777
778 101 ▶ my $hybrid_is_tieable = $args->{tieable}||$primitive_is_tied ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'tieable'} || $primitive_is_tied ? : 94 7 101
Condition100%3/3
$args->{"tieable"} or $primitive_is_tied
l!l&&r!l&&!r
36587
MC/DC100%2/2
$args->{"tieable"} or $primitive_is_tied
$args->{"tieable"} $primitive_is_tied
Truth table100%3/3
A or B
A= $args->{"tieable"}B= $primitive_is_tied
ABresult
1X1
011
000
779 101 ▶ my $hybrid_is_mutable = $args->{mutable} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'mutable'} ? : 0 101 101
780 101 ▶ my $hybrid_is_caller = $args->{caller} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'caller'} ? : 0 101 101
781 101 ▶ my $no_opt = 1
Branch: 1 branch
BranchTrueFalseTotal
unless $hybrid_is_tieable or $hybrid_is_mutable or $hybrid_is_caller 7 94 101
Condition66%4/6
$hybrid_is_tieable or $hybrid_is_mutable or $hybrid_is_caller
l!l&&r!l&&!r
9407
$hybrid_is_tieable or $hybrid_is_mutable
l!l&&r!l&&!r
9407
MC/DC33%1/3
$hybrid_is_tieable or $hybrid_is_mutable or $hybrid_is_caller
$hybrid_is_tieable $hybrid_is_mutable $hybrid_is_caller
Truth table50%2/4
A or B or C
A= $hybrid_is_tieableB= $hybrid_is_mutableC= $hybrid_is_caller
ABCresult
1XX1
01X1
0011
0000
782 if !$hybrid_is_tieable
783 and !$hybrid_is_mutable
784 and !$hybrid_is_caller;
785
786 101 { return bless $primitive
787 101 ▶ , $PromoclassCache{ref $primitive}->{$class}[$hybrid_is_tieable][
Condition100%2/2
$PromoclassCache{ref $primitive}{$class}[$hybrid_is_tieable][$hybrid_is_mutable][$hybrid_is_caller] || (next)
l!l
8615
MC/DC100%1/1
$PromoclassCache{ref $primitive}{$class}[$hybrid_is_tieable][$hybrid_is_mutable][$hybrid_is_caller] || (next)
$PromoclassCache{ref $primitive}{$class}[$hybrid_is_tieable][$hybrid_is_mutable][$hybrid_is_caller]
Truth table100%2/2
A
A= $PromoclassCache{ref $primitive}{$class}[$hybrid_is_tieable][$hybrid_is_mutable][$hybrid_is_caller]
Aresult
11
00
788 $hybrid_is_mutable][
789 $hybrid_is_caller ]||next } # slower shortcircuit
790
791 15 ▶ ref $primitive or croak("Can't promote() non-reference value $primitive");
Branch: 1 branch
BranchTrueFalseTotal
ref $primitive or croak("Can't promote() non-reference value $primitive") 15 0 15
792 !blessed($primitive) or $args->{rebless}
793 or $HybridClass{ref $primitive }
794 15 ▶ and delete $Object::Hybrid::Cache4object{refaddr($primitive)}, 1
Branch: 1 branch
BranchTrueFalseTotal
not builtin::blessed($primitive) or $args->{"rebless"} or $HybridClass{ref $primitive} and delete $Object::Hybrid::Cache4object{builtin::refaddr($primitive)}, 1 or croak("Can't promote() object $primitive") 15 0 15
Condition55%5/9
not builtin::blessed($primitive) or $args->{"rebless"} or $HybridClass{ref $primitive} and delete $Object::Hybrid::Cache4object{builtin::refaddr($primitive)}, 1
l!l&&r!l&&!r
1050
not builtin::blessed($primitive) or $args->{"rebless"}
l!l&&r!l&&!r
1005
$HybridClass{ref $primitive} and delete $Object::Hybrid::Cache4object{builtin::refaddr($primitive)}, 1
!ll&&!rl&&r
005
MC/DC0%0/4
not builtin::blessed($primitive) or $args->{"rebless"} or $HybridClass{ref $primitive} and delete $Object::Hybrid::Cache4object{builtin::refaddr($primitive)}, 1
not builtin::blessed($primitive) $args->{"rebless"} $HybridClass{ref $primitive} delete $Object::Hybrid::Cache4object{builtin::refaddr($primitive)}, 1
Truth table40%2/5
not(A) or B or C and D
A= not builtin::blessed($primitive)B= $args->{"rebless"}C= $HybridClass{ref $primitive}D= delete $Object::Hybrid::Cache4object{builtin::refaddr($primitive)}, 1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
795 or croak("Can't promote() object $primitive");
796
797 15 my $primitive_ref = ref $primitive;
798 15 my $primitive_reftype = reftype($primitive);
799
800 15 ▶ $class4type{$primitive_reftype}
Branch: 1 branch
BranchTrueFalseTotal
$class4type{$primitive_reftype} or croak("Error: promote()ing $primitive_reftype primitive is not supported") 15 0 15
801 or croak("Error: promote()ing $primitive_reftype primitive is not supported");
802
803 15 my $frontclass;
804 15 my $typename = $self->name4type(
805 reftype => $primitive_reftype,
806 tieable => $hybrid_is_tieable,
807 mutable => $hybrid_is_mutable,
808 caller => $hybrid_is_caller,
809 );
810 15 my $typeclass = $self->$typename;
811 15 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) { } 9 6 15
812 9 ▶ unless ( $self->Class->is($class) ) { # use $class as subclass...
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Class->is($class)) 9 0 9
813 9 $frontclass = $self->frontclass_name($class, $primitive_reftype);
814 9 ▶ @{ $frontclass . '::ISA' } or
Condition33%1/3
$typeclass || ()
l!l&&r!l&&!r
300
MC/DC0%0/2
$typeclass || ()
$typeclass ()
Truth table33%1/3
A || B
A= $typeclassB= ()
ABresult
1X1
011
000
815 9 ▶ @{ $frontclass . '::ISA' } = ( $class, $typeclass||() );
Branch: 1 branch
BranchTrueFalseTotal
@{$frontclass . '::ISA';} or @{$frontclass . '::ISA';} = ($class, $typeclass || ()) 6 3 9
816 }
817 6 } else { $frontclass = $typeclass; }
818
819 # custom hybrid class may subclass $typeclass or subclass of Object::Hybrid may override $typename() methods, so call load_type() anyway
820 15 $self->load_type($typename);
821
822 my
823 15 $bless = $frontclass->can('bless');
824 15 ▶ $bless ? $frontclass->$bless($primitive)
Branch: 1 branch
BranchTrueFalseTotal
$bless ? : 0 15 15
825 : bless $primitive, $frontclass;
826
827 15 $HybridClass{ ref $primitive} = ref $primitive;
828 15 ▶ $PromoclassCache2{$primitive_ref}->[ $primitive_is_tied] = ref $primitive if $no_opt and $class eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $no_opt and $class eq "" 3 12 15
Condition100%3/3
$no_opt and $class eq ""
!ll&&!rl&&r
843
MC/DC100%2/2
$no_opt and $class eq ""
$no_opt $class eq ""
Truth table100%3/3
A and B
A= $no_optB= $class eq ""
ABresult
0X0
100
111
829 15 ▶ $PromoclassCache3{$primitive_ref}->{$class}[$primitive_is_tied] = ref $primitive if $no_opt;
Branch: 1 branch
BranchTrueFalseTotal
if $no_opt 7 8 15
830 15 $PromoclassCache{ $primitive_ref}->{$class}[$hybrid_is_tieable][
831 $hybrid_is_mutable][
832 $hybrid_is_caller ] = ref $primitive;
833
834 $primitive->shadow($args->{shadow})
835 15 ▶ if exists $args->{shadow};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"shadow"} 0 15 15
836
837 15 return $primitive
838 }
839
840 12 ▶sub tie {
Subroutine tie: called CC=7 SCAR=28.7
Pod documented
841 return undef
842 12 ▶ if !ref $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[1] 0 12 12
843
844 my $tied
845 12 ▶ = reftype($_[1]) eq 'HASH' ? tie( %{$_[1]}, @_[2..$#_] ) # $_[1] =~ m'(?:^|=)HASH'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[1]) eq 'SCALAR' ? : 0 0 0
846 0 ▶ : reftype($_[1]) eq 'SCALAR' ? tie( ${$_[1]}, @_[2..$#_] ) # $_[1] =~ m'(?:^|=)SCALAR'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[1]) eq 'ARRAY' ? : 0 0 0
847 0 ▶ : reftype($_[1]) eq 'ARRAY' ? tie( @{$_[1]}, @_[2..$#_] ) # $_[1] =~ m'(?:^|=)ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[1]) eq 'GLOB' ? : 0 0 0
848 0 ▶ : reftype($_[1]) eq 'GLOB' ? tie( *{$_[1]}, @_[2..$#_] ) # $_[1] =~ m'(?:^|=)GLOB'
Branch: 2 branches
BranchTrueFalseTotal
my $tied = builtin::reftype($_[1]) eq "HASH" ? CORE::tie(%{$_[1];}, @_[2 .. $#_]) : (builtin::reftype($_[1]) eq "SCALAR" ? CORE::tie(${$_[1];}, @_[2 .. $#_]) : (builtin::reftype($_[1]) eq "ARRAY" ? CORE::tie(@{$_[1];}, @_[2 .. $#_]) : (builtin::reftype($_[1]) eq "GLOB" ? CORE::tie(*{$_[1];}, @_[2 .. $#_]) : undef))) or return undef 12 0 12
builtin::reftype($_[1]) eq 'HASH' ? : 12 0 12
849 : undef
850 or return undef;
851
852 12 Object::Hybrid->new($_[1]);
853 12 return $tied
854 }
855
856 1 my %Loaded;
857 17 ▶sub load_type {
Subroutine load_type: called CC=8 SCAR=22.6
Pod undocumented
858 17 ▶ $Loaded{$_[1]} and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$Loaded{$_[1]} and return undef 13 4 17
859 4 $Loaded{$_[1]} = 1; # immediately - to avoid infinite recursion
860
861 4 my ($self, $type) = @_;
862
863 4 ▶ my $sub_type
Branch: 2 branches
BranchTrueFalseTotal
my $sub_type = !ref($type) ? $self->can("LOAD_$type") : croak("Bad type $type") or croak("No $type() method defined") 4 0 4
!ref($type) ? : 4 0 4
864 = !ref $type ? $self->can("LOAD_$type")
865 : croak("Bad type $type")
866 or croak("No $type() method defined");
867
868 4 my $class = $self->$sub_type($type);
869 4 ▶ $class = $self->$class( $type) if ref $class eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $class eq "CODE" 0 4 4
870 4 ▶ !ref $class or croak("Unrecorgnized value '$class' returned by $type()");
Branch: 1 branch
BranchTrueFalseTotal
ref $class and croak("Unrecorgnized value '${class}' returned by $type()") 0 4 4
871 4 ▶ ! $class or eval($class), !$@ or croak("Error: Can't eval() $type(): $@");
Branch: 1 branch
BranchTrueFalseTotal
not $class or eval $class, !$@ or croak("Error: Can't eval() $type(): $@") 4 0 4
Condition33%1/3
not $class or eval $class, !$@
l!l&&r!l&&!r
040
MC/DC0%0/2
not $class or eval $class, !$@
not $class eval $class, !$@
Truth table33%1/3
not(A) or B
A= not $classB= eval $class, !$@
ABresult
1X1
011
000
872
873 4 return 1
874 }
875
876 0 ▶sub ref_tied { shift; _ref_tied(@_) }
Subroutine ref_tied: not called CC=1 SCAR=6.9
Pod documented
877 0 ▶sub _ref_tied2 { # this is much faster at least for tied hashes, but for non-tied tries all variants (still may be faster)
Subroutine _ref_tied2: not called CC=6 SCAR=37.4
878 0 ▶ return undef if !ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
879 0 return eval{ tied( %{$_[0]} ) }
880 0 || eval{ tied( ${$_[0]} ) }
881 0 || eval{ tied( @{$_[0]} ) }
882 0 ▶ || eval{ tied( *{$_[0]} ) }
Condition0%0/11
eval { do { tied %{$_[0];} } } || eval { do { tied ${$_[0];} } } || eval { do { tied @{$_[0];} } } || eval { do { tied *{$_[0];} } } || undef
l!l
00
eval { do { tied %{$_[0];} } } or eval { do { tied ${$_[0];} } } or eval { do { tied @{$_[0];} } } or eval { do { tied *{$_[0];} } }
l!l&&r!l&&!r
000
eval { do { tied %{$_[0];} } } or eval { do { tied ${$_[0];} } } or eval { do { tied @{$_[0];} } }
l!l&&r!l&&!r
000
eval { do { tied %{$_[0];} } } or eval { do { tied ${$_[0];} } }
l!l&&r!l&&!r
000
MC/DC0%0/4
eval { do { tied %{$_[0];} } } || eval { do { tied ${$_[0];} } } || eval { do { tied @{$_[0];} } } || eval { do { tied *{$_[0];} } } || undef
eval { do { tied %{$_[0];} } } eval { do { tied ${$_[0];} } } eval { do { tied @{$_[0];} } } eval { do { tied *{$_[0];} } }
Truth table0%0/5
A or B or C or D
A= eval { do { tied %{$_[0];} } }B= eval { do { tied ${$_[0];} } }C= eval { do { tied @{$_[0];} } }D= eval { do { tied *{$_[0];} } }
ABCDresult
1XXX1
01XX1
001X1
00011
00000
883 || undef
884 }
885 113 ▶sub _ref_tied {
Subroutine _ref_tied: called CC=9 SCAR=27.3
886 #return undef if !ref $_[0]; # unlikely to be called on non-reference
887 109 ▶ return reftype($_[0]) eq 'HASH' ? tied( %{$_[0]} )||0 # $_[0] =~ m'(?:^|=)HASH'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[0]) eq 'SCALAR' ? : 0 4 4
Condition0%0/2
tied ${$_[0];} or 0
l!l
00
MC/DC0%0/1
tied ${$_[0];} or 0
tied ${$_[0];}
Truth table0%0/2
A
A= tied ${$_[0];}
Aresult
11
00
888 0 ▶ : reftype($_[0]) eq 'SCALAR' ? tied( ${$_[0]} )||0 # $_[0] =~ m'(?:^|=)SCALAR'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[0]) eq 'ARRAY' ? : 0 4 4
Condition0%0/2
tied @{$_[0];} or 0
l!l
00
MC/DC0%0/1
tied @{$_[0];} or 0
tied @{$_[0];}
Truth table0%0/2
A
A= tied @{$_[0];}
Aresult
11
00
889 0 ▶ : reftype($_[0]) eq 'ARRAY' ? tied( @{$_[0]} )||0 # $_[0] =~ m'(?:^|=)ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[0]) eq 'GLOB' ? : 4 0 4
Condition100%2/2
tied *{$_[0];} or 0
l!l
22
MC/DC100%1/1
tied *{$_[0];} or 0
tied *{$_[0];}
Truth table100%2/2
A
A= tied *{$_[0];}
Aresult
11
00
890 113 ▶ : reftype($_[0]) eq 'GLOB' ? tied( *{$_[0]} )||0 # $_[0] =~ m'(?:^|=)GLOB'
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[0]) eq 'HASH' ? : 109 4 113
Condition100%2/2
tied %{$_[0];} or 0
l!l
8029
MC/DC100%1/1
tied %{$_[0];} or 0
tied %{$_[0];}
Truth table100%2/2
A
A= tied %{$_[0];}
Aresult
11
00
891 : undef
892 }
893
894 0 ▶sub ref_type { reftype($_[1]) }
Subroutine ref_type: not called CC=1 SCAR=6.9
Pod documented
895 #sub ref_type { shift; reftype(@_) }
896 0 ▶sub _ref_type {
Subroutine _ref_type: not called CC=3 SCAR=24.8
897 0 ▶ return undef if !ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
898 0 ▶ return $1 if $_[0] =~ /=(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /=(\w+)/ 0 0 0
899 0 return ref $_[0]
900 }
901
902 0 ▶sub ref_isa { shift; _ref_isa(@_) }
Subroutine ref_isa: not called CC=1 SCAR=6.9
Pod documented
903 0 ▶sub _ref_isa {
Subroutine _ref_isa: not called CC=5 SCAR=34.0
904 0 ▶ return undef if !ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
905 0 ▶ return '' if exists $class4type{ref $_[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $class4type{ref $_[0]} 0 0 0
906 0 ▶ return 0 if defined $_[1] and !$_[0]->isa($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] and not $_[0]->isa($_[1]) 0 0 0
Condition0%0/3
defined $_[1] and not $_[0]->isa($_[1])
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[1] and not $_[0]->isa($_[1])
defined $_[1] not $_[0]->isa($_[1])
Truth table0%0/3
A and not(B)
A= defined $_[1]B= not $_[0]->isa($_[1])
ABresult
0X0
100
111
907 0 return $_[0]
908 }
909
910 10 ▶sub croak { require Carp; goto &Carp::croak; }
Subroutine croak: called CC=1 SCAR=0.0
Pod undocumented
911
912 135 ▶sub _alter_case { $_[0] =~ /[A-Z]/ ? lc($_[0]) : uc($_[0]) };
Subroutine _alter_case: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /[A-Z]/ ? : 59 76 135
913 0 ▶sub method_alias { _alter_case($_[1]) }
Subroutine method_alias: not called CC=1 SCAR=6.9
Pod undocumented
914
915 7 ▶sub methods {
Subroutine methods: called CC=5 SCAR=16.3
Pod undocumented
916 7 shift;
917 7 my $subs;
918 7 ▶ ref $_[0] eq 'HASH' ? ($subs) : %$subs = @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 2 5 7
919 7 my $caller = caller;
920 7 foreach my $method (keys %$subs) {
921 # explicit aliases...
922 ref $subs->{$method} eq 'CODE'
923 or ref( $subs->{$method}
924 56 ▶ = $subs->{$subs->{$method}}) eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $subs->{$method} eq "CODE" or ref($subs->{$method} = $$subs{$subs->{$method}}) eq "CODE" or next 56 0 56
Condition33%1/3
ref $subs->{$method} eq "CODE" or ref($subs->{$method} = $$subs{$subs->{$method}}) eq "CODE"
l!l&&r!l&&!r
5600
MC/DC0%0/2
ref $subs->{$method} eq "CODE" or ref($subs->{$method} = $$subs{$subs->{$method}}) eq "CODE"
ref $subs->{$method} eq "CODE" ref($subs->{$method} = $$subs{$subs->{$method}}) eq "CODE"
Truth table33%1/3
A or B
A= ref $subs->{$method} eq "CODE"B= ref($subs->{$method} = $$subs{$subs->{$method}}) eq "CODE"
ABresult
1X1
011
000
925 or next;
926
927 # implicit altered-case aliases...
928 56 my $method2 = _alter_case($method);
929 56 my $goto;
930 56 *{join '::', $caller, $method } =
931 56 *{join '::', $caller, $method2} = $subs->{$method};
932
933 }
934 }
935
936 10 ▶sub _cant_locate_object_method {
Subroutine _cant_locate_object_method: called CC=3 SCAR=15.4
937 10 ▶ join '', "Object::Hybrid: Can't locate object method \""
Condition33%2/6
ref $_[0] || $_[0]
l!l&&r!l&&!r
1000
ref $_[0] || $_[0]
l!l&&r!l&&!r
1000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
938 , $_[1], "\" via package \""
939 , ref($_[0])||$_[0], "\" (perhaps you forgot to load \""
940 , ref($_[0])||$_[0], "\"?) "
941 }
942
943 {
944 package Object::Hybrid::BASE;
945
946 Object::Hybrid->methods(
947 0 ▶ shadow => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
948 0 ▶ return $Object::Hybrid::Shadow4object{refaddr($_[0])} = $_[1] if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
949 0 return $Object::Hybrid::Shadow4object{refaddr($_[0])};
950 },
951 2 ▶ call => sub{
Subroutine __ANON__: called CC=2 SCAR=7.0
952 package Object::Hybrid;
953 2 ▶ @_ > 1 or croak("Error: Nothing to call");
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 or croak("Error: Nothing to call") 2 0 2
954
955 2 local $Object::Hybrid::Portable = 1;
956 2 my $method = lc(splice(@_, 1, 1));
957 2 return shift->$method(@_) # is ok, except for caller()
958 },
959 1 );
960
961 1 our $AUTOLOAD;
962 16 ▶ sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
963 package Object::Hybrid;
964 16 ▶ $Object::Hybrid::Portable and (split '::', $AUTOLOAD)[-1] !~ /[A-Z]/ and return # lower-case aliases are fail-safe for compartibility
Branch: 1 branch
BranchTrueFalseTotal
$Object::Hybrid::Portable and not +(split(/::/, $Object::Hybrid::BASE::AUTOLOAD, 0))[-1] =~ /[A-Z]/ and return or croak(_cant_locate_object_method($_[0], $Object::Hybrid::BASE::AUTOLOAD)) 0 8 8
Condition100%5/5
$Object::Hybrid::Portable and not +(split(/::/, $Object::Hybrid::BASE::AUTOLOAD, 0))[-1] =~ /[A-Z]/ and return
!ll
88
$Object::Hybrid::Portable and not +(split(/::/, $Object::Hybrid::BASE::AUTOLOAD, 0))[-1] =~ /[A-Z]/
!ll&&!rl&&r
268
MC/DC100%2/2
$Object::Hybrid::Portable and not +(split(/::/, $Object::Hybrid::BASE::AUTOLOAD, 0))[-1] =~ /[A-Z]/ and return
$Object::Hybrid::Portable not +(split(/::/, $Object::Hybrid::BASE::AUTOLOAD, 0))[-1] =~ /[A-Z]/
Truth table100%3/3
A and not(B)
A= $Object::Hybrid::PortableB= not +(split(/::/, $Object::Hybrid::BASE::AUTOLOAD, 0))[-1] =~ /[A-Z]/
ABresult
0X0
100
111
965 or croak( _cant_locate_object_method($_[0], $AUTOLOAD) );
966 }
967
968 25 ▶ sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
969 package Object::Hybrid;
970 25 delete $Object::Hybrid::Shadow4object{refaddr($_[0])};
971 return
972 25 }
973 }
974
975 1 my $CLASS_TEMPLATE = <<'CLASS_TEMPLATE';
976
977 $INC{ INCKEY_REPLACE } ||= 1;
978 package PACKAGE_REPLACE;
979
980 our @ISA = 'Object::Hybrid::BASE';
981
982 use Object::Hybrid::Class; # just labeling
983 use Scalar::Util qw(reftype refaddr);
984
985 sub can;
986 #sub isa;
987
988 #sub FETCH { tied(%{$_[0]})->FETCH(@_[1..$#_]) } # 100_000 calls 0.94 CPU sec 106_157/s.
989 #sub FETCH { splice(@_, 0, 1, tied(%{$_[0]})); goto &{ $_[0]->can('FETCH') } } # 100_000 calls 2.08 CPU sec 48_007/s. goto() or plain ->() call are irrelevent - major cost is that of can().
990
991 Object::Hybrid->methods(
992 tied => sub { TIED_REPLACE },
993 SELF => sub {
994
995 =This is too much of the guess-work, it is safer to just return $_[0]
996 my $self;
997 return $self
998 if $self
999 = Object::Hybrid::_ref_tied($_[0])
1000 and reftype($_[0])
1001 eq reftype($self)
1002 and ref($self) =~ /Std/;
1003
1004 !$self or Object::Hybrid::croak("tied() class defines nor valid self() method for $_[0] (self() returned $self)");
1005
1006 =cut
1007
1008 return $_[0]
1009 },
1010 fast => sub {
1011 return TIED_REPLACE || $_[0];
1012
1013 return eval{ tied( %{$_[0]} ) }
1014 || eval{ tied( ${$_[0]} ) }
1015 || eval{ tied( @{$_[0]} ) }
1016 || eval{ tied( *{$_[0]} ) }
1017 || $_[0];
1018
1019 return $_[0] if !ref $_[0];
1020 my $type = reftype($_[0]);
1021 return $type eq 'HASH' ? tied( %{$_[0]} ) || $_[0]
1022 : $type eq 'SCALAR' ? tied( ${$_[0]} ) || $_[0]
1023 : $type eq 'ARRAY' ? tied( @{$_[0]} ) || $_[0]
1024 : $type eq 'GLOB' ? tied( *{$_[0]} ) || $_[0]
1025 : $_[0];
1026 },
1027 call => sub{
1028 @_ > 1
1029 or Object::Hybrid::croak("Error: Nothing to call");
1030
1031 local $Object::Hybrid::Portable = 1;
1032 my $method = lc(splice(@_, 1, 1));
1033 return shift->$method(@_) # is ok, except for caller()
1034 },
1035 );
1036
1037 #my $AUTOLOAD = \&AUTOLOAD;
1038 sub AUTOLOAD {
1039 package Object::Hybrid; # to not qualify _ref_tied(), reftype(), croak(), etc...
1040
1041 ( my $METHOD = $PACKAGE_REPLACE::AUTOLOAD ) =~ s/^.*:://;
1042 my $METHOD_is_lc = ($METHOD !~ /[A-Z]/);
1043 my $METHOD2 = _alter_case($METHOD);
1044 my $SUB_METHOD;
1045
1046 my $FALLBACK_METHOD;
1047
1048 my $SUB_METHOD_NAME = join '::', ref($_[0])||$_[0], $METHOD;
1049 my $SYMTABLE = \%{(ref($_[0])||$_[0]) . '::'};
1050
1051 goto &{ *$SUB_METHOD_NAME
1052 = $SUB_METHOD
1053 = $METHOD eq 'can'
1054 ? sub{
1055
1056 my $err;
1057 my $can_method2;
1058 my $can_method = $_[1];
1059 my $sub_method = ($_[0])->UNIVERSAL::can($can_method)
1060 || ($_[0])->UNIVERSAL::can($can_method2
1061 = _alter_case($can_method));
1062 eval{ $sub_method ||= (TIED_REPLACE||$_[0])->UNIVERSAL::can($can_method)
1063 or $sub_method ||= (TIED_REPLACE||$_[0])->UNIVERSAL::can($can_method2) }; $err=$@;
1064 eval{ $sub_method ||= (SUBCLASS_REPLACE->UNIVERSAL::can($can_method )
1065 || SUBCLASS_REPLACE->UNIVERSAL::can($can_method2)) };
1066
1067 croak("BUG in can() of mutable hybrid class: " . $err||$@) if $err||$@;
1068
1069 return $sub_method
1070 }
1071 : IS_MUTABLE_REPLACE && !KEEP_CALLER_REPLACE
1072 ? sub{
1073 my $err;
1074 { return wantarray
1075 ? ( eval{ TIED_REPLACE->$METHOD(@_[1..$#_]) } , $@ ? next :() )
1076 : ( scalar(eval{ TIED_REPLACE->$METHOD(@_[1..$#_]) }), $@ ? next :() )[0] };
1077
1078 { return wantarray
1079 ? ( eval{ TIED_REPLACE->$METHOD2(@_[1..$#_]) } , $@ ? next :() )
1080 : ( scalar(eval{ TIED_REPLACE->$METHOD2(@_[1..$#_]) }), $@ ? next :() )[0] };
1081
1082 { return wantarray
1083 ? ( eval{ ($FALLBACK_METHOD ||= SUBCLASS_REPLACE->UNIVERSAL::can($METHOD)
1084 || die("Cannot find method $METHOD() via $_[0]"))->(@_) } , $@ ? next :() )
1085 : ( scalar( eval{ ($FALLBACK_METHOD ||= SUBCLASS_REPLACE->UNIVERSAL::can($METHOD)
1086 || die("Cannot find method $METHOD() via $_[0]"))->(@_) }), $@ ? next :() )[0] };
1087
1088 $err = $@;
1089
1090 { return wantarray
1091 ? ( eval{ ($FALLBACK_METHOD ||= SUBCLASS_REPLACE->UNIVERSAL::can($METHOD2)
1092 || die("Cannot find method $METHOD() via $_[0]"))->(@_) } , $@ ? next :() )
1093 : ( scalar( eval{ ($FALLBACK_METHOD ||= SUBCLASS_REPLACE->UNIVERSAL::can($METHOD2)
1094 || die("Cannot find method $METHOD() via $_[0]"))->(@_) }), $@ ? next :() )[0] };
1095
1096 $err ||= $@;
1097
1098 delete $SYMTABLE->{$METHOD};
1099
1100 $METHOD_is_lc and $Object::Hybrid::Portable and return; # lower-case aliases are fail-safe for compartibility
1101 #or croak( _cant_locate_object_method($_[0], $METHOD) );
1102
1103 croak($err||"Failed to call $METHOD() on $_[0] (this is a BUG)")
1104 }
1105 : sub{
1106
1107 my $cache = ($Object::Hybrid::Cache4object{refaddr($_[0])}->{$METHOD} ||= []) unless IS_MUTABLE_REPLACE;
1108
1109 KEEP_CALLER_REPLACE || $Object::Hybrid::CALLER
1110 ? ( splice(@_, 0, 1, $cache->[0] )
1111 , goto &{$cache->[1]} ) # about twice slower, but preserves caller()
1112 : ( shift @_, return $cache->[1]->(
1113 $cache->[0], @_) )
1114 if !IS_MUTABLE_REPLACE and @$cache;
1115
1116 my $sub_method;
1117 {
1118 my
1119 $swap;
1120 $swap = TIED_REPLACE and
1121 $swap = splice(@_, 0, 1, $swap);
1122
1123 $swap and $sub_method
1124 = $_[0]->UNIVERSAL::can($METHOD)
1125 || $_[0]->UNIVERSAL::can($METHOD2)
1126 and last;
1127
1128 $swap and splice(@_, 0, 1, $swap); # revert swap, if any
1129
1130 $sub_method
1131 = SUBCLASS_REPLACE->UNIVERSAL::can($METHOD)
1132 || SUBCLASS_REPLACE->UNIVERSAL::can($METHOD2)
1133 and last;
1134
1135 delete $SYMTABLE->{$METHOD};
1136
1137 $METHOD_is_lc and $Object::Hybrid::Portable and return # lower-case aliases are fail-safe for compatibility
1138 or croak( _cant_locate_object_method($_[0], $METHOD) );
1139 }
1140
1141 $sub_method ne $SUB_METHOD # this case is hopefully excluded by above logic, but it may screw up
1142 #and defined(&$sub_method) # here goto() to not defined(&method) is ok as it may be autoloadable in tied() class or otherwise
1143 or $sub_method = undef
1144 , croak( join '', "Undefined method \""
1145 , $METHOD, "\" called via package \""
1146 , ref($_[0])||$_[0], "\"");
1147
1148 $cache->[0] = $_[0],
1149 $cache->[1] = $sub_method,
1150 #weaken($cache->[0]),
1151 #weaken($cache->[1]),
1152 unless IS_MUTABLE_REPLACE;
1153
1154 goto &$sub_method
1155 } };
1156 }
1157
1158 sub DESTROY {
1159 #delete $Object::Hybrid::Tied4object{ refaddr($_[0])};
1160 delete $Object::Hybrid::Shadow4object{refaddr($_[0])};
1161 delete $Object::Hybrid::Cache4object{ refaddr($_[0])};
1162 return
1163 }
1164
1165 CLASS_TEMPLATE
1166
1167 4 ▶sub _compile_class {
Subroutine _compile_class: called CC=11 SCAR=38.0
1168 4 my ($self, $class_template, $type) = @_;
1169 4 $type = uc($type);
1170
1171 4 ▶ $type =~ /(HASH|ARRAY|GLOB|SCALAR)/ and my $reftype = $1 or croak("Bad $type name");
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /(HASH|ARRAY|GLOB|SCALAR)/ and my $reftype = $1 or croak("Bad $type name") 4 0 4
Condition33%1/3
$type =~ /(HASH|ARRAY|GLOB|SCALAR)/ and my $reftype = $1
!ll&&!rl&&r
004
MC/DC0%0/2
$type =~ /(HASH|ARRAY|GLOB|SCALAR)/ and my $reftype = $1
$type =~ /(HASH|ARRAY|GLOB|SCALAR)/ my $reftype = $1
Truth table33%1/3
A and B
A= $type =~ /(HASH|ARRAY|GLOB|SCALAR)/B= my $reftype = $1
ABresult
0X0
100
111
1172
1173 4 my $PACKAGE_REPLACE = $self->$type;
1174 4 ( my $INCKEY_REPLACE =
1175 $PACKAGE_REPLACE . '.pm' ) =~ s/::/\//g;
1176 4 my $SUBCLASS_REPLACE = "${reftype}_UNTIED";
1177 4 ▶ my $IS_MUTABLE_REPLACE = $type =~ /MUTABLE/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /MUTABLE/ ? : 0 4 4
1178 4 ▶ my $KEEP_CALLER_REPLACE = $type =~ /CALLER/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /CALLER/ ? : 0 4 4
1179 4 ▶ my $TIED_REPLACE
Branch: 4 branches
BranchTrueFalseTotal
$reftype eq 'HASH' ? : 2 2 4
$reftype eq 'ARRAY' ? : 0 2 2
$reftype eq 'GLOB' ? : 2 0 2
$reftype eq 'SCALAR' ? : 0 0 0
1180 = $reftype eq 'HASH' ? 'tied( %{$_[0]} )'
1181 : $reftype eq 'ARRAY' ? 'tied( @{$_[0]} )'
1182 : $reftype eq 'GLOB' ? 'tied( *{$_[0]} )'
1183 : $reftype eq 'SCALAR' ? 'tied( ${$_[0]} )'
1184 : croak("Bad $reftype reftype");
1185
1186 4 ▶ $self->load_type($SUBCLASS_REPLACE)
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq $SUBCLASS_REPLACE 2 2 4
1187 unless $type eq $SUBCLASS_REPLACE;
1188
1189 4 $class_template =~ s/PACKAGE_REPLACE/$PACKAGE_REPLACE/g;
1190 4 $class_template =~ s/INCKEY_REPLACE/'$INCKEY_REPLACE'/g;
1191 4 $class_template =~ s/SUBCLASS_REPLACE/$SUBCLASS_REPLACE/g;
1192 4 $class_template =~ s/TIED_REPLACE/$TIED_REPLACE/g;
1193 4 $class_template =~ s/IS_MUTABLE_REPLACE/$IS_MUTABLE_REPLACE/g;
1194 4 $class_template =~ s/KEEP_CALLER_REPLACE/$KEEP_CALLER_REPLACE/g;
1195 0 ▶ eval $class_template;
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine AUTOLOAD: called CC=4 SCAR=21.9
Subroutine AUTOLOAD: called CC=4 SCAR=21.9
Subroutine DESTROY: called CC=1 SCAR=2.7
Subroutine DESTROY: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=2 SCAR=11.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=15 SCAR=44.3
Subroutine __ANON__: not called CC=2 SCAR=11.7
Subroutine __ANON__: called CC=12 SCAR=40.3
Subroutine __ANON__: not called CC=25 SCAR=53.8
Subroutine __ANON__: called CC=16 SCAR=45.5
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=6 SCAR=28.4
Subroutine __ANON__: called CC=3 SCAR=17.5
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=5 SCAR=25.4
Subroutine __ANON__: not called CC=3 SCAR=17.5
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=3 SCAR=17.5
Subroutine __ANON__: not called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: not called CC=15 SCAR=44.3
Subroutine __ANON__: called CC=2 SCAR=11.7
Subroutine __ANON__: called CC=12 SCAR=40.3
Subroutine __ANON__: not called CC=25 SCAR=53.8
Subroutine __ANON__: called CC=16 SCAR=45.5
Subroutine new: not called CC=2 SCAR=11.7
Pod undocumented
Branch: 73 branches
BranchTrueFalseTotal
$METHOD eq 'can' ? : 1 1 2
$METHOD eq 'can' ? : 1 28 29
unless ref $_[0] 0 0 0
$type eq 'HASH' ? : 0 0 0
$type eq 'SCALAR' ? : 0 0 0
$type eq 'ARRAY' ? : 0 0 0
$type eq 'GLOB' ? : 0 0 0
@_ > 1 or Object::Hybrid::croak("Error: Nothing to call") 0 0 0
$sub_method ||= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method) or $sub_method ||= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method2) 130 4 134
if $err or $@ 0 134 134
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
$METHOD_is_lc and $Object::Hybrid::Portable and return 0 0 0
if @$cache 0 42 42
$Object::Hybrid::CALLER ? : 0 0 0
$swap = tied %{$_[0];} and $swap = splice(@_, 0, 1, $swap) 36 6 42
$swap and $sub_method = $_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2) and last 36 6 42
$swap and splice @_, 0, 1, $swap 0 6 6
$sub_method = "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD) || "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD2) and last 6 0 6
$METHOD_is_lc and $Object::Hybrid::Portable and return or croak(_cant_locate_object_method($_[0], $METHOD)) 0 0 0
$sub_method ne $SUB_METHOD or $sub_method = undef, croak(join("", "Undefined method \"", $METHOD, "\" called via package \"", ref $_[0] || $_[0], "\"")) 42 0 42
if ($fh eq '') { } 0 0 0
eval { do { $fh = *$fh } }, !$@ or Object::Hybrid::croak("Not a GLOB reference") 0 0 0
if @open_args 0 0 0
defined $_[0]->FILENO and $_[0]->CLOSE 6 4 10
@_ == 2 ? : 0 10 10
@_ >= 3 or Object::Hybrid::croak("Not enough arguments for sysopen()") 6 0 6
@_ == 3 ? : 6 0 6
@_ >= 4 ? : 0 0 0
not $@ or Object::Hybrid::croak($@) 6 0 6
@_ >= 3 or Object::Hybrid::croak("Not enough arguments for fcntl()") 0 0 0
not $@ or Object::Hybrid::croak($@) 0 0 0
if ($_[1] =~ /^-\w$/) { } 0 0 0
not $@ or Object::Hybrid::croak($@) 0 0 0
unless ref $_[0] 0 0 0
$type eq 'HASH' ? : 0 0 0
$type eq 'SCALAR' ? : 0 0 0
$type eq 'ARRAY' ? : 0 0 0
$type eq 'GLOB' ? : 0 0 0
@_ > 1 or Object::Hybrid::croak("Error: Nothing to call") 2 0 2
$sub_method ||= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method) or $sub_method ||= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method2) 0 3 3
if $err or $@ 0 3 3
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
wantarray ? : 0 0 0
$@ ? : 0 0 0
$@ ? : 0 0 0
$METHOD_is_lc and $Object::Hybrid::Portable and return 0 0 0
if @$cache 31 50 81
$Object::Hybrid::CALLER ? : 0 31 31
$swap = tied *{$_[0];} and $swap = splice(@_, 0, 1, $swap) 50 0 50
$swap and $sub_method = $_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2) and last 44 6 50
$swap and splice @_, 0, 1, $swap 6 0 6
$sub_method = "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD) || "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD2) and last 2 4 6
$METHOD_is_lc and $Object::Hybrid::Portable and return or croak(_cant_locate_object_method($_[0], $METHOD)) 0 2 2
$sub_method ne $SUB_METHOD or $sub_method = undef, croak(join("", "Undefined method \"", $METHOD, "\" called via package \"", ref $_[0] || $_[0], "\"")) 46 0 46
Condition22%50/227
ref $_[0] || $_[0]
l!l&&r!l&&!r
110
ref $_[0] || $_[0]
l!l&&r!l&&!r
110
ref $_[0] || $_[0]
l!l&&r!l&&!r
2810
ref $_[0] || $_[0]
l!l&&r!l&&!r
2810
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
CORE::tied %{$_[0];} || $_[0]
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } || eval { do { CORE::tied ${$_[0];} } } || eval { do { CORE::tied @{$_[0];} } } || eval { do { CORE::tied *{$_[0];} } } || $_[0]
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } or eval { do { CORE::tied ${$_[0];} } } or eval { do { CORE::tied @{$_[0];} } } or eval { do { CORE::tied *{$_[0];} } }
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } or eval { do { CORE::tied ${$_[0];} } } or eval { do { CORE::tied @{$_[0];} } }
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } or eval { do { CORE::tied ${$_[0];} } }
l!l&&r!l&&!r
000
CORE::tied %{$_[0];} or $_[0]
l!l&&r!l&&!r
000
CORE::tied ${$_[0];} or $_[0]
l!l&&r!l&&!r
000
CORE::tied @{$_[0];} or $_[0]
l!l&&r!l&&!r
000
CORE::tied *{$_[0];} or $_[0]
l!l&&r!l&&!r
000
$_[0]->UNIVERSAL::can($can_method) || $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
l!l&&r!l&&!r
89414
$sub_method ||= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
l!l&&r!l&&!r
13004
tied %{$_[0];} || $_[0]
l!l&&r!l&&!r
040
$sub_method ||= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
l!l&&r!l&&!r
004
tied %{$_[0];} || $_[0]
l!l&&r!l&&!r
040
$sub_method ||= "Object::Hybrid::HASH"->UNIVERSAL::can($can_method) || "Object::Hybrid::HASH"->UNIVERSAL::can($can_method2)
l!l&&r!l&&!r
13022
'Object::Hybrid::HASH'->UNIVERSAL::can($can_method) || 'Object::Hybrid::HASH'->UNIVERSAL::can($can_method2)
l!l&&r!l&&!r
202
$err or $@
l!l&&r!l&&!r
00134
'BUG in can() of mutable hybrid class: ' . $err || $@
l!l&&r!l&&!r
000
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$err ||= $@
l!l&&r!l&&!r
000
$METHOD_is_lc and $Object::Hybrid::Portable
!ll&&!rl&&r
000
$err || "Failed to call $METHOD() on $_[0] (this is a BUG)"
l!l
00
$Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD} ||= []
l!l
042
$swap and $sub_method = $_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2)
!ll&&!rl&&r
6036
$_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2)
l!l&&r!l&&!r
3600
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD) || 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
l!l&&r!l&&!r
600
$METHOD_is_lc and $Object::Hybrid::Portable and return
!ll
00
$METHOD_is_lc and $Object::Hybrid::Portable
!ll&&!rl&&r
000
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
@open_args && ($fh->OPEN(@open_args) || Object::Hybrid::croak($!))
!ll&&!rl&&r
000
$fh->OPEN(@open_args) or Object::Hybrid::croak($!)
l!l
00
ref $elf || $elf
l!l&&r!l&&!r
000
CORE::tied *{$_[0];} || $_[0]
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } || eval { do { CORE::tied ${$_[0];} } } || eval { do { CORE::tied @{$_[0];} } } || eval { do { CORE::tied *{$_[0];} } } || $_[0]
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } or eval { do { CORE::tied ${$_[0];} } } or eval { do { CORE::tied @{$_[0];} } } or eval { do { CORE::tied *{$_[0];} } }
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } or eval { do { CORE::tied ${$_[0];} } } or eval { do { CORE::tied @{$_[0];} } }
l!l&&r!l&&!r
000
eval { do { CORE::tied %{$_[0];} } } or eval { do { CORE::tied ${$_[0];} } }
l!l&&r!l&&!r
000
CORE::tied %{$_[0];} or $_[0]
l!l&&r!l&&!r
000
CORE::tied ${$_[0];} or $_[0]
l!l&&r!l&&!r
000
CORE::tied @{$_[0];} or $_[0]
l!l&&r!l&&!r
000
CORE::tied *{$_[0];} or $_[0]
l!l&&r!l&&!r
000
$_[0]->UNIVERSAL::can($can_method) || $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
l!l&&r!l&&!r
003
$sub_method ||= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
l!l&&r!l&&!r
003
tied *{$_[0];} || $_[0]
l!l&&r!l&&!r
210
$sub_method ||= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
l!l&&r!l&&!r
003
tied *{$_[0];} || $_[0]
l!l&&r!l&&!r
210
$sub_method ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($can_method) || "Object::Hybrid::GLOB"->UNIVERSAL::can($can_method2)
l!l&&r!l&&!r
003
'Object::Hybrid::GLOB'->UNIVERSAL::can($can_method) || 'Object::Hybrid::GLOB'->UNIVERSAL::can($can_method2)
l!l&&r!l&&!r
003
$err or $@
l!l&&r!l&&!r
003
'BUG in can() of mutable hybrid class: ' . $err || $@
l!l&&r!l&&!r
000
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l&&r!l&&!r
000
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
l!l
00
$err ||= $@
l!l&&r!l&&!r
000
$METHOD_is_lc and $Object::Hybrid::Portable
!ll&&!rl&&r
000
$err || "Failed to call $METHOD() on $_[0] (this is a BUG)"
l!l
00
$Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD} ||= []
l!l
3150
$swap and $sub_method = $_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2)
!ll&&!rl&&r
0644
$_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2)
l!l&&r!l&&!r
22226
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD) || 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
l!l&&r!l&&!r
204
$METHOD_is_lc and $Object::Hybrid::Portable and return
!ll
22
$METHOD_is_lc and $Object::Hybrid::Portable
!ll&&!rl&&r
202
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
$_[0]->can('TIEGLOB') || Object::Hybrid::croak('Method not defined: new() / TIEGLOB()')
l!l
00
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
CORE::tied %{$_[0];} || $_[0]
CORE::tied %{$_[0];} $_[0]
MC/DC0%0/5
eval { do { CORE::tied %{$_[0];} } } || eval { do { CORE::tied ${$_[0];} } } || eval { do { CORE::tied @{$_[0];} } } || eval { do { CORE::tied *{$_[0];} } } || $_[0]
eval { do { CORE::tied %{$_[0];} } } eval { do { CORE::tied ${$_[0];} } } eval { do { CORE::tied @{$_[0];} } } eval { do { CORE::tied *{$_[0];} } } $_[0]
MC/DC0%0/2
CORE::tied %{$_[0];} or $_[0]
CORE::tied %{$_[0];} $_[0]
MC/DC0%0/2
CORE::tied ${$_[0];} or $_[0]
CORE::tied ${$_[0];} $_[0]
MC/DC0%0/2
CORE::tied @{$_[0];} or $_[0]
CORE::tied @{$_[0];} $_[0]
MC/DC0%0/2
CORE::tied *{$_[0];} or $_[0]
CORE::tied *{$_[0];} $_[0]
MC/DC100%2/2
$_[0]->UNIVERSAL::can($can_method) || $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
$_[0]->UNIVERSAL::can($can_method) $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
MC/DC50%1/2
$sub_method ||= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
$sub_method (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
MC/DC0%0/2
tied %{$_[0];} || $_[0]
tied %{$_[0];} $_[0]
MC/DC0%0/2
$sub_method ||= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
$sub_method (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
MC/DC0%0/2
tied %{$_[0];} || $_[0]
tied %{$_[0];} $_[0]
MC/DC0%0/3
$sub_method ||= "Object::Hybrid::HASH"->UNIVERSAL::can($can_method) || "Object::Hybrid::HASH"->UNIVERSAL::can($can_method2)
$sub_method 'Object::Hybrid::HASH'->UNIVERSAL::can($can_method) 'Object::Hybrid::HASH'->UNIVERSAL::can($can_method2)
MC/DC0%0/2
$err or $@
$err $@
MC/DC0%0/2
'BUG in can() of mutable hybrid class: ' . $err || $@
'BUG in can() of mutable hybrid class: ' . $err $@
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD)
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD)
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::HASH"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
MC/DC0%0/2
$err ||= $@
$err $@
MC/DC0%0/1
$err || "Failed to call $METHOD() on $_[0] (this is a BUG)"
$err
MC/DC0%0/1
$Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD} ||= []
$Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD}
MC/DC33%1/3
$swap and $sub_method = $_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2)
$swap $_[0]->UNIVERSAL::can($METHOD) $_[0]->UNIVERSAL::can($METHOD2)
MC/DC0%0/2
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD) || 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD) 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
MC/DC0%0/2
$METHOD_is_lc and $Object::Hybrid::Portable and return
$METHOD_is_lc $Object::Hybrid::Portable
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
@open_args && ($fh->OPEN(@open_args) || Object::Hybrid::croak($!))
@open_args $fh->OPEN(@open_args)
MC/DC0%0/2
ref $elf || $elf
ref $elf $elf
MC/DC0%0/2
CORE::tied *{$_[0];} || $_[0]
CORE::tied *{$_[0];} $_[0]
MC/DC0%0/5
eval { do { CORE::tied %{$_[0];} } } || eval { do { CORE::tied ${$_[0];} } } || eval { do { CORE::tied @{$_[0];} } } || eval { do { CORE::tied *{$_[0];} } } || $_[0]
eval { do { CORE::tied %{$_[0];} } } eval { do { CORE::tied ${$_[0];} } } eval { do { CORE::tied @{$_[0];} } } eval { do { CORE::tied *{$_[0];} } } $_[0]
MC/DC0%0/2
CORE::tied %{$_[0];} or $_[0]
CORE::tied %{$_[0];} $_[0]
MC/DC0%0/2
CORE::tied ${$_[0];} or $_[0]
CORE::tied ${$_[0];} $_[0]
MC/DC0%0/2
CORE::tied @{$_[0];} or $_[0]
CORE::tied @{$_[0];} $_[0]
MC/DC0%0/2
CORE::tied *{$_[0];} or $_[0]
CORE::tied *{$_[0];} $_[0]
MC/DC0%0/2
$_[0]->UNIVERSAL::can($can_method) || $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
$_[0]->UNIVERSAL::can($can_method) $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
MC/DC0%0/2
$sub_method ||= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
$sub_method (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
MC/DC0%0/2
tied *{$_[0];} || $_[0]
tied *{$_[0];} $_[0]
MC/DC0%0/2
$sub_method ||= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
$sub_method (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
MC/DC0%0/2
tied *{$_[0];} || $_[0]
tied *{$_[0];} $_[0]
MC/DC0%0/3
$sub_method ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($can_method) || "Object::Hybrid::GLOB"->UNIVERSAL::can($can_method2)
$sub_method 'Object::Hybrid::GLOB'->UNIVERSAL::can($can_method) 'Object::Hybrid::GLOB'->UNIVERSAL::can($can_method2)
MC/DC0%0/2
$err or $@
$err $@
MC/DC0%0/2
'BUG in can() of mutable hybrid class: ' . $err || $@
'BUG in can() of mutable hybrid class: ' . $err $@
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD)
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD)
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
MC/DC0%0/2
$FALLBACK_METHOD ||= "Object::Hybrid::GLOB"->UNIVERSAL::can($METHOD2) || die("Cannot find method $METHOD() via $_[0]")
$FALLBACK_METHOD 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
MC/DC0%0/2
$err ||= $@
$err $@
MC/DC0%0/1
$err || "Failed to call $METHOD() on $_[0] (this is a BUG)"
$err
MC/DC100%1/1
$Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD} ||= []
$Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD}
MC/DC66%2/3
$swap and $sub_method = $_[0]->UNIVERSAL::can($METHOD) || $_[0]->UNIVERSAL::can($METHOD2)
$swap $_[0]->UNIVERSAL::can($METHOD) $_[0]->UNIVERSAL::can($METHOD2)
MC/DC50%1/2
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD) || 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD) 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
MC/DC50%1/2
$METHOD_is_lc and $Object::Hybrid::Portable and return
$METHOD_is_lc $Object::Hybrid::Portable
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/1
$_[0]->can('TIEGLOB') || Object::Hybrid::croak('Method not defined: new() / TIEGLOB()')
$_[0]->can('TIEGLOB')
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= CORE::tied %{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/6
A or B or C or D || E
A= eval { do { CORE::tied %{$_[0];} } }B= eval { do { CORE::tied ${$_[0];} } }C= eval { do { CORE::tied @{$_[0];} } }D= eval { do { CORE::tied *{$_[0];} } }E= $_[0]
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
Truth table0%0/3
A or B
A= CORE::tied %{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= CORE::tied ${$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= CORE::tied @{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= CORE::tied *{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table100%3/3
A || B
A= $_[0]->UNIVERSAL::can($can_method)B= $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
ABresult
1X1
011
000
Truth table66%2/3
A ||= B
A= $sub_methodB= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= tied %{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $sub_methodB= (tied %{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= tied %{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/4
A ||= B || C
A= $sub_methodB= 'Object::Hybrid::HASH'->UNIVERSAL::can($can_method)C= 'Object::Hybrid::HASH'->UNIVERSAL::can($can_method2)
ABCresult
1XX1
01X1
0011
0000
Truth table33%1/3
A or B
A= $errB= $@
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= 'BUG in can() of mutable hybrid class: ' . $errB= $@
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $errB= $@
ABresult
1X1
011
000
Truth table0%0/2
A
A= $err
Aresult
11
00
Truth table50%1/2
A
A= $Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD}
Aresult
11
00
Truth table50%2/4
A and B || C
A= $swapB= $_[0]->UNIVERSAL::can($METHOD)C= $_[0]->UNIVERSAL::can($METHOD2)
ABCresult
0XX0
1000
11X1
1011
Truth table33%1/3
A || B
A= 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD)B= 'Object::Hybrid::HASH'->UNIVERSAL::can($METHOD2)
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= $METHOD_is_lcB= $Object::Hybrid::Portable
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A && B
A= @open_argsB= $fh->OPEN(@open_args)
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= ref $elfB= $elf
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= CORE::tied *{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/6
A or B or C or D || E
A= eval { do { CORE::tied %{$_[0];} } }B= eval { do { CORE::tied ${$_[0];} } }C= eval { do { CORE::tied @{$_[0];} } }D= eval { do { CORE::tied *{$_[0];} } }E= $_[0]
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
Truth table0%0/3
A or B
A= CORE::tied %{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= CORE::tied ${$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= CORE::tied @{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= CORE::tied *{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $_[0]->UNIVERSAL::can($can_method)B= $_[0]->UNIVERSAL::can($can_method2 = _alter_case($can_method))
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $sub_methodB= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= tied *{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $sub_methodB= (tied *{$_[0];} || $_[0])->UNIVERSAL::can($can_method2)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= tied *{$_[0];}B= $_[0]
ABresult
1X1
011
000
Truth table0%0/4
A ||= B || C
A= $sub_methodB= 'Object::Hybrid::GLOB'->UNIVERSAL::can($can_method)C= 'Object::Hybrid::GLOB'->UNIVERSAL::can($can_method2)
ABCresult
1XX1
01X1
0011
0000
Truth table33%1/3
A or B
A= $errB= $@
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= 'BUG in can() of mutable hybrid class: ' . $errB= $@
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $FALLBACK_METHODB= 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $errB= $@
ABresult
1X1
011
000
Truth table0%0/2
A
A= $err
Aresult
11
00
Truth table100%2/2
A
A= $Object::Hybrid::Cache4object{builtin::refaddr($_[0])}{$METHOD}
Aresult
11
00
Truth table75%3/4
A and B || C
A= $swapB= $_[0]->UNIVERSAL::can($METHOD)C= $_[0]->UNIVERSAL::can($METHOD2)
ABCresult
0XX0
1000
11X1
1011
Truth table66%2/3
A || B
A= 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD)B= 'Object::Hybrid::GLOB'->UNIVERSAL::can($METHOD2)
ABresult
1X1
011
000
Truth table66%2/3
A and B
A= $METHOD_is_lcB= $Object::Hybrid::Portable
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/2
A
A= $_[0]->can('TIEGLOB')
Aresult
11
00
1196 4 ▶ !$@ or die($@);
Branch: 1 branch
BranchTrueFalseTotal
not $@ or die $@ 4 0 4
1197 }
1198
1199 1 ▶sub LOAD_HASH_STATIC { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_HASH_STATIC: called CC=1 SCAR=0.0
Pod undocumented
1200 0 ▶sub LOAD_HASH_STATIC_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_HASH_STATIC_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1201 0 ▶sub LOAD_HASH_MUTABLE { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_HASH_MUTABLE: not called CC=1 SCAR=6.9
Pod undocumented
1202 0 ▶sub LOAD_HASH_MUTABLE_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_HASH_MUTABLE_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1203
1204 0 ▶sub LOAD_ARRAY_STATIC { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_ARRAY_STATIC: not called CC=1 SCAR=6.9
Pod undocumented
1205 0 ▶sub LOAD_ARRAY_STATIC_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_ARRAY_STATIC_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1206 0 ▶sub LOAD_ARRAY_MUTABLE { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_ARRAY_MUTABLE: not called CC=1 SCAR=6.9
Pod undocumented
1207 0 ▶sub LOAD_ARRAY_MUTABLE_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_ARRAY_MUTABLE_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1208
1209 1 ▶sub LOAD_GLOB_STATIC { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_GLOB_STATIC: called CC=1 SCAR=0.0
Pod undocumented
1210 0 ▶sub LOAD_GLOB_STATIC_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_GLOB_STATIC_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1211 0 ▶sub LOAD_GLOB_MUTABLE { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_GLOB_MUTABLE: not called CC=1 SCAR=6.9
Pod undocumented
1212 0 ▶sub LOAD_GLOB_MUTABLE_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_GLOB_MUTABLE_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1213
1214 0 ▶sub LOAD_SCALAR_STATIC { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_SCALAR_STATIC: not called CC=1 SCAR=6.9
Pod undocumented
1215 0 ▶sub LOAD_SCALAR_STATIC_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_SCALAR_STATIC_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1216 0 ▶sub LOAD_SCALAR_MUTABLE { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_SCALAR_MUTABLE: not called CC=1 SCAR=6.9
Pod undocumented
1217 0 ▶sub LOAD_SCALAR_MUTABLE_CALLER { $_[0]->_compile_class($CLASS_TEMPLATE, $_[1]); }
Subroutine LOAD_SCALAR_MUTABLE_CALLER: not called CC=1 SCAR=6.9
Pod undocumented
1218
1219 1 ▶sub LOAD_HASH_UNTIED { $_[0]->_compile_class(<<'CLASS', $_[1]);
Subroutine LOAD_HASH_UNTIED: called CC=1 SCAR=0.0
Pod undocumented
1220
1221 package PACKAGE_REPLACE;
1222 $INC{INCKEY_REPLACE} ||= 1;
1223 our @ISA = 'Object::Hybrid::BASE';
1224
1225 use Object::Hybrid::Class; # just labeling
1226 use Scalar::Util qw(reftype refaddr);
1227
1228 #sub can { $_[0]->UNIVERSAL::can($_[1]) }
1229
1230 Object::Hybrid->methods({
1231 tied => sub { undef },
1232 fast => sub { $_[0] },
1233 self => sub { $_[0] },
1234 TIEHASH => sub { bless {}, ref($_[0])||$_[0] },
1235 STORE => sub { $_[0]->{$_[1]} = $_[2] },
1236 FETCH => sub { $_[0]->{$_[1]} },
1237 FIRSTKEY => sub { my $a = scalar keys %{$_[0]}; each %{$_[0]} },
1238 NEXTKEY => sub { each %{$_[0]} },
1239 EXISTS => sub { exists $_[0]->{$_[1]} },
1240 DELETE => sub { delete $_[0]->{$_[1]} },
1241 CLEAR => sub { %{$_[0]} = () },
1242 SCALAR => sub { scalar %{$_[0]} },
1243 });
1244
1245 CLASS
1246
1247 }
1248
1249 0 ▶sub LOAD_SCALAR_UNTIED { $_[0]->_compile_class(<<'CLASS', $_[1]);
Subroutine LOAD_SCALAR_UNTIED: not called CC=1 SCAR=6.9
Pod undocumented
1250
1251 package PACKAGE_REPLACE;
1252 $INC{INCKEY_REPLACE} ||= 1;
1253 our @ISA = 'Object::Hybrid::BASE';
1254
1255 use Object::Hybrid::Class; # just labeling
1256 use Scalar::Util qw(reftype refaddr);
1257
1258 #sub can { $_[0]->UNIVERSAL::can($_[1]) }
1259
1260 Object::Hybrid->methods({
1261 tied => sub { undef },
1262 fast => sub { $_[0] },
1263 self => sub { $_[0] },
1264 TIESCALAR => sub {
1265 my $class = shift;
1266 my $instance = shift || undef;
1267 return bless \$instance => $class;
1268 },
1269 FETCH => sub { ${$_[0]} },
1270 STORE => sub { ${$_[0]} = $_[1] },
1271 });
1272
1273 CLASS
1274
1275 }
1276
1277 0 ▶sub LOAD_ARRAY_UNTIED { $_[0]->_compile_class(<<'CLASS', $_[1]);
Subroutine LOAD_ARRAY_UNTIED: not called CC=1 SCAR=6.9
Pod undocumented
1278
1279 package PACKAGE_REPLACE;
1280 $INC{INCKEY_REPLACE} ||= 1;
1281 our @ISA = 'Object::Hybrid::BASE';
1282
1283 use Object::Hybrid::Class; # just labeling
1284 use Scalar::Util qw(reftype refaddr);
1285
1286 #sub can { $_[0]->UNIVERSAL::can($_[1]) }
1287
1288 Object::Hybrid->methods({
1289 tied => sub { undef },
1290 fast => sub { $_[0] },
1291 self => sub { $_[0] },
1292 TIEARRAY => sub { bless [], $_[0] },
1293 FETCHSIZE => sub { scalar @{$_[0]} },
1294 STORESIZE => sub { $#{$_[0]} = $_[1]-1 },
1295 STORE => sub { $_[0]->[$_[1]] = $_[2] },
1296 FETCH => sub { $_[0]->[$_[1]] },
1297 CLEAR => sub { @{$_[0]} = () },
1298 POP => sub { pop(@{$_[0]}) },
1299 PUSH => sub { my $o = shift; push(@$o,@_) },
1300 SHIFT => sub { shift(@{$_[0]}) },
1301 UNSHIFT => sub { my $o = shift; unshift(@$o,@_) },
1302 EXISTS => sub { exists $_[0]->[$_[1]] },
1303 DELETE => sub { delete $_[0]->[$_[1]] },
1304 EXTEND => sub {},
1305 SPLICE => sub {
1306 my $ob = shift;
1307 my $sz = $ob->FETCHSIZE;
1308 my $off = @_ ? shift : 0;
1309 $off += $sz if $off < 0;
1310 my $len = @_ ? shift : $sz-$off;
1311 return splice(@$ob,$off,$len,@_);
1312 },
1313 });
1314
1315 CLASS
1316
1317 }
1318
1319 1 ▶sub LOAD_GLOB_UNTIED { $_[0]->_compile_class(<<'CLASS', $_[1]);
Subroutine LOAD_GLOB_UNTIED: called CC=1 SCAR=0.0
Pod undocumented
1320
1321 package PACKAGE_REPLACE;
1322 $INC{INCKEY_REPLACE} ||= 1;
1323 our @ISA = 'Object::Hybrid::BASE';
1324
1325 use Object::Hybrid::Class; # just labeling
1326 use Scalar::Util qw(reftype refaddr);
1327
1328 #sub can { $_[0]->UNIVERSAL::can($_[1]) }
1329
1330 sub new {
1331 goto &{ $_[0]->can(qw(TIEGLOB))
1332 ||Object::Hybrid::croak("Method not defined: new() / TIEGLOB()") }
1333 }
1334
1335 Object::Hybrid->methods({
1336 tied => sub { undef },
1337 fast => sub { $_[0] },
1338 self => sub { $_[0] },
1339 TIEGLOB => sub {
1340 my ($elf, $fh, @open_args) = @_;
1341
1342 if ($fh eq '') {
1343 $fh = \do { local *GLOB };
1344 } else {
1345 eval{ $fh = *$fh }, !$@ or Object::Hybrid::croak("Not a GLOB reference");
1346 }
1347
1348 $fh->OPEN(@open_args) or Object::Hybrid::croak($!)
1349 if @open_args;
1350
1351 return bless $fh, ref($elf)||$elf
1352 },
1353
1354 OPEN => sub {
1355 defined $_[0]->FILENO
1356 and $_[0]->CLOSE;
1357
1358 @_ == 2
1359 ? open($_[0], $_[1])
1360 : open($_[0], $_[1], $_[2]);
1361 },
1362
1363 WRITE2 => sub {
1364 my $fh = $_[0];
1365 print $fh substr($_[1],0,$_[2])
1366 },
1367 WRITE => sub { my $fh = shift; write $fh },
1368 PRINT => sub { my $fh = shift; print $fh @_ },
1369 PRINTF => sub { my $fh = shift; printf $fh @_ },
1370
1371 READ => sub { read $_[0], $_[1], $_[2] },
1372 READLINE => sub { my $fh = $_[0]; <$fh> },
1373 GETC => sub { getc $_[0] },
1374
1375 EOF => sub { eof $_[0] },
1376 TELL => sub { tell $_[0] },
1377 FILENO => sub { fileno $_[0] },
1378 SEEK => sub { seek $_[0], $_[1], $_[2] },
1379 CLOSE => sub { close $_[0] },
1380 BINMODE => sub { binmode $_[0] },
1381
1382 SYSOPEN => sub {
1383 eval {
1384 @_ >= 3 or Object::Hybrid::croak("Not enough arguments for sysopen()");
1385 @_ == 3 ? sysopen $_[0]->self, $_[1], $_[2] :
1386 @_ >= 4 ? sysopen $_[0]->self, $_[1], $_[2], $_[3] :();
1387 };
1388 !$@ or Object::Hybrid::croak($@);
1389 },
1390 FCNTL => sub {
1391 eval {
1392 @_ >= 3 or Object::Hybrid::croak("Not enough arguments for fcntl()");
1393 fcntl $_[0]->self, $_[1], $_[2];
1394 };
1395 !$@ or Object::Hybrid::croak($@);
1396 }, # TODO: same as for SYSOPEN()
1397 STAT => sub { stat $_[0]->self },
1398 FLOCK => sub { flock $_[0]->self, $_[1] },
1399 TRUNCATE => sub { truncate $_[0]->self, $_[1] },
1400 FTEST => sub {
1401 my $file = $_[0]->self;
1402 if ($_[1] =~ /^-\w$/) {
1403 eval "$_[1] \$file";
1404 !$@ or Object::Hybrid::croak($@);
1405 }
1406 else { Object::Hybrid::croak("Unknown argument to FTEST()") }
1407 },
1408
1409 });
1410
1411 #sub UNTIE;
1412
1413 CLASS
1414
1415 }
1416
1417 1 1;
1418
↑ Summary Class/Tag.pm »