line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Data::Hopen::Class - Class::Tiny base class supporting new(-arg => value) |
2
|
|
|
|
|
|
|
package Data::Hopen::Class; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
4770
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
23
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.000019'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# No parent, so Class::Tiny will become the parent |
12
|
1
|
|
|
1
|
|
541
|
use Class::Tiny; |
|
1
|
|
|
|
|
1844
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Docs {{{1 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Data::Hopen::Class - Class::Tiny base class supporting C<< new(-arg => value) >> |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This is the same as L except for a custom C method |
23
|
|
|
|
|
|
|
that permits you to put hyphens in front of the argument names in the |
24
|
|
|
|
|
|
|
constructor call. This provides consistency with L. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# }}}1 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 FUNCTIONS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 BUILDARGS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Pre-process the constructor arguments to strip leading hyphens from |
35
|
|
|
|
|
|
|
argument names. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Note: L prohibits attributes named C<-> (a single hyphen), |
38
|
|
|
|
|
|
|
so we don't handle that case. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# The internal builder, so I don't have to worry about dispatch |
43
|
|
|
|
|
|
|
# once our BUILDARGS is called. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _data_hopen_class_builder_internal { |
46
|
16
|
100
|
|
16
|
|
133
|
my $class = shift or croak 'Need a class'; |
47
|
|
|
|
|
|
|
|
48
|
15
|
100
|
100
|
|
|
96
|
if(@_ == 1 && ref $_[0] eq 'HASH') { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
49
|
3
|
|
|
|
|
7
|
@_ = ($class, %{$_[0]}); |
|
3
|
|
|
|
|
12
|
|
50
|
3
|
|
|
|
|
10
|
goto \&_data_hopen_class_builder_internal; |
51
|
|
|
|
|
|
|
# No extra stack frame for the sake of croak() |
52
|
|
|
|
|
|
|
} elsif(@_ == 1 && ref $_[0]) { |
53
|
1
|
|
|
|
|
5
|
croak "$class\->new(arg) with @{[ref $_[0]]} instead of HASH ref"; |
|
1
|
|
|
|
|
100
|
|
54
|
|
|
|
|
|
|
} elsif(@_ % 2) { |
55
|
1
|
|
|
|
|
238
|
croak "Odd number of arguments to $class\->new()"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Now we have key-value pairs. Trim leading hyphens on the keys. |
59
|
10
|
|
|
|
|
29
|
my %args = @_; |
60
|
10
|
|
|
|
|
30
|
for (keys %args) { |
61
|
12
|
100
|
|
|
|
46
|
next unless /^-/; |
62
|
6
|
|
|
|
|
19
|
$args{ substr $_, 1 } = $args{ $_ }; |
63
|
6
|
|
|
|
|
16
|
delete $args{ $_ }; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
10
|
|
|
|
|
28
|
return \%args; |
67
|
|
|
|
|
|
|
}; # $_builder() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub BUILDARGS { |
70
|
13
|
|
|
13
|
1
|
13859
|
goto \&Data::Hopen::Class::_data_hopen_class_builder_internal; |
71
|
|
|
|
|
|
|
} #BUILDARGS() |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |