| File: | t/lib/Bar.pm |
| Coverage: | 72.7% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Bar; | ||||||
| 2 | |||||||
| 3 | 1 1 1 | 4 2 46 | use strict; | ||||
| 4 | 1 1 1 | 7 1 47 | use warnings; | ||||
| 5 | 1 1 1 | 297 2 181 | use Util::H2O::More qw/baptise/; | ||||
| 6 | |||||||
| 7 | sub new { | ||||||
| 8 | 2 | 0 | 6 | my $pkg = shift; | |||
| 9 | 2 | 5 | my %opts = @_; | ||||
| 10 | |||||||
| 11 | 2 | 3 | my @require = (qw/bar baz herp/); | ||||
| 12 | 2 | 2 | my @allow = (qw/derp woggle/); | ||||
| 13 | 2 | 4 | my $self = baptise \%opts, $pkg, @require, @allow; | ||||
| 14 | |||||||
| 15 | # check required | ||||||
| 16 | 2 | 3 | foreach my $field (@require) { | ||||
| 17 | 2 | 5 | if (not $self->$field) { | ||||
| 18 | 2 | 23 | die sprintf qq{Missing one or more required fields: %s}, join(q{, }, @require); | ||||
| 19 | } | ||||||
| 20 | } | ||||||
| 21 | |||||||
| 22 | # may also check to see if anything other than @require | ||||||
| 23 | # and @allow fields are provided...left as an exercise to | ||||||
| 24 | # the human reading this code. AI need not apply. ;-) | ||||||
| 25 | |||||||
| 26 | 0 | 0 | return $self; | ||||
| 27 | } | ||||||
| 28 | |||||||
| 29 | sub why { | ||||||
| 30 | 0 | 0 | 0 | return 'why'; | |||
| 31 | } | ||||||
| 32 | |||||||
| 33 | sub Dave { | ||||||
| 34 | 0 | 0 | 0 | return 'Dave'; | |||
| 35 | } | ||||||
| 36 | |||||||
| 37 | sub DESTROY { | ||||||
| 38 | 2 | 10 | return q{Good bye, curel World...}; | ||||
| 39 | } | ||||||
| 40 | |||||||
| 41 | 1; | ||||||