File Coverage

blib/lib/Perl6/Pod/Utl/Context.pm
Criterion Covered Total %
statement 121 137 88.3
branch 8 10 80.0
condition 3 5 60.0
subroutine 37 43 86.0
pod 10 10 100.0
total 179 205 87.3


line stmt bran cond sub pod time code
1             package Perl6::Pod::Utl::Context;
2             our $VERSION = '0.01';
3 3     3   16 use warnings;
  3         6  
  3         116  
4 3     3   17 use strict;
  3         5  
  3         78  
5 3     3   2148 use Perl6::Pod::Directive::use;
  3         8  
  3         91  
6 3     3   1880 use Perl6::Pod::Directive::config;
  3         9  
  3         94  
7 3     3   1908 use Perl6::Pod::Directive::alias;
  3         8  
  3         88  
8 3     3   1896 use Perl6::Pod::Block::comment;
  3         8  
  3         85  
9 3     3   1793 use Perl6::Pod::Block::code;
  3         12  
  3         93  
10 3     3   1614 use Perl6::Pod::Block::para;
  3         7  
  3         83  
11 3     3   1591 use Perl6::Pod::Block::head;
  3         8  
  3         74  
12 3     3   1722 use Perl6::Pod::Block::table;
  3         7  
  3         85  
13 3     3   1717 use Perl6::Pod::Block::output;
  3         9  
  3         74  
14 3     3   1589 use Perl6::Pod::Block::input;
  3         8  
  3         77  
15 3     3   1682 use Perl6::Pod::Block::nested;
  3         7  
  3         91  
16 3     3   1824 use Perl6::Pod::Block::item;
  3         8  
  3         84  
17 3     3   1712 use Perl6::Pod::FormattingCode::A;
  3         8  
  3         75  
18 3     3   1660 use Perl6::Pod::FormattingCode::C;
  3         7  
  3         84  
19 3     3   1671 use Perl6::Pod::FormattingCode::D;
  3         6  
  3         80  
20 3     3   1790 use Perl6::Pod::FormattingCode::K;
  3         7  
  3         84  
21 3     3   1771 use Perl6::Pod::FormattingCode::M;
  3         8  
  3         103  
22 3     3   1773 use Perl6::Pod::FormattingCode::L;
  3         6  
  3         89  
23             #use Perl6::Pod::FormattingCode::P;
24 3     3   1736 use Perl6::Pod::FormattingCode::B;
  3         6  
  3         80  
25 3     3   1755 use Perl6::Pod::FormattingCode::I;
  3         8  
  3         81  
26 3     3   1879 use Perl6::Pod::FormattingCode::S;
  3         9  
  3         85  
27 3     3   1596 use Perl6::Pod::FormattingCode::U;
  3         7  
  3         112  
28 3     3   1728 use Perl6::Pod::FormattingCode::X;
  3         9  
  3         103  
29 3     3   1947 use Perl6::Pod::FormattingCode::E;
  3         13  
  3         129  
30 3     3   1913 use Perl6::Pod::FormattingCode::R;
  3         10  
  3         126  
31 3     3   1861 use Perl6::Pod::FormattingCode::T;
  3         9  
  3         89  
32 3     3   1668 use Perl6::Pod::FormattingCode::N;
  3         8  
  3         86  
33 3     3   1638 use Perl6::Pod::FormattingCode::Z;
  3         10  
  3         83  
34              
35 3     3   2034 use Tie::UnionHash;
  3         9120  
  3         135  
36 3     3   22 use Data::Dumper;
  3         5  
  3         463  
37             =pod
38             use => 'Perl6::Pod::Directive::use',
39             comment => 'Perl6::Pod::Block::comment',
40             'M<>' => 'Perl6::Pod::FormattingCode::M',
41              
42             # 'P<>' => 'Perl6::Pod::FormattingCode::P',
43             'S<>' => 'Perl6::Pod::FormattingCode::S',
44             'V<>' => 'Perl6::Pod::FormattingCode::C', #V like C
45             =cut
46              
47             use constant {
48 3         2051 DEFAULT_USE => {
49             'File' => '-',
50             'config'=>'Perl6::Pod::Directive::config',
51             code => 'Perl6::Pod::Block::code',
52             'para' => 'Perl6::Pod::Block::para',
53             alias => 'Perl6::Pod::Directive::alias',
54             nested => 'Perl6::Pod::Block::nested',
55             output => 'Perl6::Pod::Block::output',
56             input => 'Perl6::Pod::Block::input',
57             item => 'Perl6::Pod::Block::item',
58             defn => 'Perl6::Pod::Block::item',
59             head => 'Perl6::Pod::Block::head',
60             table => 'Perl6::Pod::Block::table',
61             'A<>' => 'Perl6::Pod::FormattingCode::A',
62             'B<>' => 'Perl6::Pod::FormattingCode::B',
63             'C<>' => 'Perl6::Pod::FormattingCode::C',
64             'D<>' => 'Perl6::Pod::FormattingCode::D',
65             'E<>' => 'Perl6::Pod::FormattingCode::E',
66             'I<>' => 'Perl6::Pod::FormattingCode::I',
67             'K<>' => 'Perl6::Pod::FormattingCode::K',
68             'L<>' => 'Perl6::Pod::FormattingCode::L',
69             'N<>' => 'Perl6::Pod::FormattingCode::N',
70             'R<>' => 'Perl6::Pod::FormattingCode::R',
71             'T<>' => 'Perl6::Pod::FormattingCode::T',
72             'U<>' => 'Perl6::Pod::FormattingCode::U',
73             'V<>' => 'Perl6::Pod::FormattingCode::C',
74             'X<>' => 'Perl6::Pod::FormattingCode::X',
75             'Z<>' => 'Perl6::Pod::FormattingCode::Z',
76             '*' => 'Perl6::Pod::Block',
77             '*<>' => 'Perl6::Pod::FormattingCode',
78              
79             # use => 'Perl6::Pod::Directive::use',
80             # config => 'Perl6::Pod::Directive::config',
81             # comment => 'Perl6::Pod::Block::comment',
82             # alias => 'Perl6::Pod::Directive::alias',
83             # code => 'Perl6::Pod::Block::code',
84             # para => 'Perl6::Pod::Block::para',
85             # table => 'Perl6::Pod::Block::table',
86             # output => 'Perl6::Pod::Block::output',
87             # input => 'Perl6::Pod::Block::input',
88             # nested => 'Perl6::Pod::Block::nested',
89             # item => 'Perl6::Pod::Block::item',
90             # defn => 'Perl6::Pod::Block::item',
91             # 'C<>' => 'Perl6::Pod::FormattingCode::C',
92             # 'D<>' => 'Perl6::Pod::FormattingCode::D',
93             # 'K<>' => 'Perl6::Pod::FormattingCode::K',
94             # 'M<>' => 'Perl6::Pod::FormattingCode::M',
95             # 'L<>' => 'Perl6::Pod::FormattingCode::L',
96             # 'B<>' => 'Perl6::Pod::FormattingCode::B',
97             # 'I<>' => 'Perl6::Pod::FormattingCode::I',
98             # 'X<>' => 'Perl6::Pod::FormattingCode::X',
99              
100             # 'P<>' => 'Perl6::Pod::FormattingCode::P',
101             # 'U<>' => 'Perl6::Pod::FormattingCode::U',
102             # 'E<>' => 'Perl6::Pod::FormattingCode::E',
103             # 'N<>' => 'Perl6::Pod::FormattingCode::N',
104             # 'A<>' => 'Perl6::Pod::FormattingCode::A',
105             # 'R<>' => 'Perl6::Pod::FormattingCode::R',
106             # 'S<>' => 'Perl6::Pod::FormattingCode::S',
107             # 'T<>' => 'Perl6::Pod::FormattingCode::T',
108             # 'V<>' => 'Perl6::Pod::FormattingCode::C', #V like C
109             # 'Z<>' => 'Perl6::Pod::FormattingCode::Z',
110              
111             }
112 3     3   17 };
  3         8  
113              
114             =head2 new [ ]
115              
116             =cut
117              
118             sub new {
119 2     2 1 7 my $class = shift;
120 2 50       7 $class = ref $class if ref $class;
121              
122             #set default contexts
123 2         22 my %args = (
124             _usef => {},
125             _alias => {},
126             _use => DEFAULT_USE,
127             _config => {},
128             _encoding => 'UTF-8',
129             _custom => {},
130             _class_opts => {},
131             _allow_context => {},
132             @_
133             );
134              
135             #create union hashes
136 2         13 while ( my ( $key, $val ) = each %args ) {
137 16 100 66     56 next unless ( ref($val) || ref($val) eq 'HASH' );
138 14         24 my %new_map = ();
139 14         60 tie %new_map, 'Tie::UnionHash', $val, {};
140 14         670 $args{$key} = \%new_map;
141              
142             }
143 2         6 my $self = bless( \%args, $class );
144 2         9 return $self;
145             }
146              
147             =head2 sub_context
148              
149             create sub_context
150              
151             =cut
152              
153             sub sub_context {
154 0     0 1 0 my $self = shift;
155 0         0 return __PACKAGE__->new(%$self);
156             }
157              
158             =head2 get_config block_name
159              
160             Get options for B in current context
161              
162             $context->get_config('item1');
163              
164             return ref to config options for ะก
165             ( implement :like attr)
166              
167             =cut
168              
169             sub get_config {
170             #TODO check for infinity loop
171 9     9 1 13 my $self = shift;
172 9   50     26 my $class_name = shift || return {};
173 9 100       10 my %class_config = %{ $self->config->{$class_name} || {} };
  9         23  
174 9 100       283 if ( my $like = delete $class_config{like} ) {
175 2 50       11 my @likes = ref($like) eq 'ARRAY' ? @$like : ($like);
176 2         5 foreach my $lname (@likes) {
177 2         5 %class_config =( %class_config, %{ $self->get_config($lname) } );
  2         9  
178             }
179             }
180 9         41 \%class_config;
181             }
182              
183             =head2 config
184              
185             return ref to hash of pod options per blockname
186              
187             =cut
188              
189             sub config {
190 12     12 1 62 return $_[0]->{_config};
191             }
192              
193             =head2 usef
194              
195             return ref to hash of plugin per formatcode name
196              
197             =cut
198              
199             sub usef {
200 0     0 1 0 return $_[0]->{_usef};
201             }
202              
203             =head2 use
204              
205             return ref to hash of perl module per blockname
206              
207             =cut
208              
209             sub use {
210 5     5 1 16 return $_[0]->{_use};
211             }
212              
213             =head2 custom
214              
215             return ref to hash of user defined keys,vals
216              
217             =cut
218              
219             sub custom {
220 0     0 1   return $_[0]->{_custom};
221             }
222              
223             =head2 class_opts
224              
225             return ref to hash of Class optioons to create loaded by use mods
226              
227             =cut
228              
229             sub class_opts {
230 0     0 1   return $_[0]->{_class_opts};
231             }
232              
233             =head2 set_use , ':config_options'
234              
235             =cut
236              
237             sub set_use {
238 0     0 1   my $self = shift;
239 0           my ( $name, $opt ) = @_;
240              
241             #now cut block_name
242 0           my ( $b1, @bn ) = @{ $self->_opt2array($opt) };
  0            
243 0           my $key = $b1->{name};
244 0           my $block_opt = join " " => map { $_->{pod} } @bn;
  0            
245 0           $self->use->{$key} = $name;
246 0           $self->{_use_init}->{$name} = $block_opt;
247 0           return { $key => $block_opt };
248             }
249              
250             =head2 encoding
251              
252             return ref to hash of pod options per blockname
253              
254             =cut
255              
256             sub encoding {
257 0     0 1   return $_[0]->{_encoding};
258             }
259              
260              
261             1;
262             __END__