blib/lib/MOP4Import/Base/IOHandle.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 97 CC 4 SCAR 17.9
CC
4
Cov
0%
build_fh_for
20.0
declare___accessor
2.0
PROP
2.0
CRAP 6.0
1 package MOP4Import::Base::IOHandle;
2 use strict;
3 use warnings;
4  
5 #----------------------------------------
6 use MOP4Import::Util ();
7 use MOP4Import::Opts;
8  
9 sub declare___accessor {
10 (my $myPack, my Opts $opts, my ($name)) = m4i_args(@_);
11 return sub :method {
12 *{$_[0]}{HASH}->{$name};
13 }
14 }
15  
16 #========================================
17 use parent 'IO::Handle';
18  
19 use MOP4Import::Base::Configure -as_base
20 , [fields =>
21 qw(
22 encoding
23 _buffer
24 )
25 ];
26  
27 #----------------------------------------
28  
29 use overload qw(
30 %{} prop
31 bool as_bool
32 );
33  
34 sub PROP () {__PACKAGE__}
35 sub prop { *{shift()}{HASH} }
36 sub as_bool { 1 }
37  
38 #========================================
39  
40 sub cf_make_object {
41 my ($class) = @_;
42 my PROP $prop = $class->build_prop;
43 my $self = $class->build_fh_for($prop);
44 }
45  
46 sub build_prop {
47 my ($class) = @_;
48 my $fields = MOP4Import::Util::maybe_fields_hash($class)
49 or Carp::croak "Class $class does'nt have \%FIELDS";
50 my PROP $prop = Hash::Util::lock_keys(my %prop, keys %$fields);
51 $prop;
52 }
53  
54 # $class->build_fh_for($prop, ?$fh?);
55 sub build_fh_for {
56 (my $class, my PROP $prop) = splice @_, 0, 2;
57 my $enc = $prop->{encoding} ? ":encoding($prop->{encoding})" : '';
58 if (not defined $_[0]) {
59 $prop->{_buffer} //= (\ my $str);
60 $ {$prop->{_buffer}} //= "";
61 open $_[0], ">$enc", $prop->{_buffer} or Carp::croak $!;
62 } elsif ($enc) {
63 binmode $_[0], $enc;
64 }
65 bless $_[0], $class;
66 *{$_[0]} = $prop;
67 $_[0];
68 }
69  
70 sub as_bytes {
71 my PROP $prop = (my $glob = shift)->prop;
72 $glob->flush;
73 $ {$prop->{_buffer}};
74 }
75  
76 1;