File Coverage

blib/lib/Lingua/JA/Expand/Base.pm
Criterion Covered Total %
statement 22 54 40.7
branch 0 12 0.0
condition 0 10 0.0
subroutine 6 10 60.0
pod 3 3 100.0
total 31 89 34.8


line stmt bran cond sub pod time code
1             package Lingua::JA::Expand::Base;
2 3     3   18 use strict;
  3         6  
  3         106  
3 3     3   15 use warnings;
  3         5  
  3         85  
4 3     3   15 use base qw(Class::Accessor::Fast Class::Data::Inheritable);
  3         6  
  3         6725  
5 3     3   25362 use Carp;
  3         8  
  3         638  
6              
7             __PACKAGE__->mk_classdata( _config => {} );
8              
9             sub new {
10 0     0 1 0 my $class = shift;
11 0         0 my $args = shift;
12 0         0 my %config = ();
13 0 0       0 if ( ref $args eq 'HASH' ) {
14 0         0 %config = %$args;
15             }
16 0         0 my $self = $class->SUPER::new();
17 0         0 $self->config(%config);
18 0         0 return $self;
19             }
20              
21             sub mk_virtual_methods {
22 1     1 1 2 my $class = shift;
23 1         3 foreach my $method (@_) {
24 1         3 my $slot = "${class}::${method}";
25             {
26 3     3   20 no strict 'refs';
  3         6  
  3         1797  
  1         3  
27 1         9 *{$slot} = sub {
28 0     0   0 Carp::croak( ref( $_[0] ) . "::${method} is not overridden" );
29             }
30 1         5 }
31             }
32 1         3 return ();
33             }
34              
35             sub config {
36 0     0 1   my $class = shift;
37 0 0         if (@_) {
38 0 0 0       if ( @_ == 1 && !defined $_[0] ) {
39 0           $class->_config(undef);
40             }
41             else {
42 0           my %args = @_;
43 0           $class->_config( $class->_merge_hashes( $class->_config, \%args ) );
44             }
45             }
46 0           return $class->_config;
47             }
48              
49             sub _merge_hashes {
50 0     0     my $class = shift;
51 0           my ( $lefthash, $righthash ) = @_;
52              
53 0 0         if ( !defined $righthash ) {
54 0           return $lefthash;
55             }
56              
57 0 0         if ( !defined $lefthash ) {
58 0           return $righthash;
59             }
60              
61 0           my %merged = %{$lefthash};
  0            
62 0           for my $key ( keys %{$righthash} ) {
  0            
63 0   0       my $right_ref = ( ref $righthash->{$key} || '' ) eq 'HASH';
64 0   0       my $left_ref =
65             ( ( exists $lefthash->{$key} && ref $lefthash->{$key} ) || '' ) eq
66             'HASH';
67 0 0 0       if ( $right_ref and $left_ref ) {
68 0           $merged{$key} =
69             merge_hashes( $lefthash->{$key}, $righthash->{$key} );
70             }
71             else {
72 0           $merged{$key} = $righthash->{$key};
73             }
74             }
75              
76 0           return \%merged;
77             }
78              
79              
80             1;
81              
82             __END__