File Coverage

gen/attr-PerlBean_Collection.pl
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1 1     1   4 use strict;
  1         2  
  1         110  
2              
3             push(@::bean_desc, {
4             bean_opt => {
5             abstract => 'Code hierarchy generation for bean like Perl modules',
6             package => 'PerlBean::Collection',
7             use_perl_version => 5.005,
8             description => <
9             C contains a collection of C objects in order to generate an hierarchy of Perl modules.
10             EOF
11             short_description => 'contains a collection of PerlBean objects',
12             synopsis => &get_syn(),
13             },
14             attr_opt => [
15             {
16             method_factory_name => 'perl_bean',
17             type => 'MULTI',
18             unique => 1,
19             associative => 1,
20             method_key => 1,
21             id_method => 'get_package',
22             allow_isa => [qw(PerlBean)],
23             short_description => 'the list of PerlBean objects in the collection',
24             },
25             {
26             method_factory_name => 'license',
27             type => 'SINGLE',
28             allow_rx => [qw(.*)],
29             short_description => 'the software license for the PerlBean collection',
30             },
31             ],
32             meth_opt => [
33             {
34             method_name => 'write',
35             parameter_description => 'DIRECTORY',
36             description => <
37             Write the hierarchy of Perl class code to C. C is a directory name. On error an exception C is thrown.
38             EOF
39             body => <<'THE_EOF',
40             my $self = shift;
41             my $dir = shift || '.';
42              
43             # Check for directory existence
44             ( -d $dir ) ||
45             throw Error::Simple("ERROR: PerlBean::Collection::write, directory '$dir' does not exist.");
46              
47             # Check for directory write-ability
48             ( -w $dir ) ||
49             throw Error::Simple("ERROR: PerlBean::Collection::write, directory '$dir' is not writable.");
50              
51             # Finalize the PerlBeans
52             foreach my $bean ( $self->values_perl_bean() ) {
53             $bean->_finalize();
54             }
55              
56             # Generate the PerlBeans
57             foreach my $bean ( $self->values_perl_bean() ) {
58             my $pkg = $bean->get_package();
59             my @dir = split(/:+/, $pkg);
60             my $fn = pop(@dir);
61             my $dir_tot = $dir;
62              
63             # Make directory
64             foreach my $sub_dir (@dir) {
65             $dir_tot .= '/' . $sub_dir;
66             next if ( -d $dir_tot );
67             mkdir($dir_tot);
68             }
69              
70             # Make the file handle and write bean
71             use IO::File;
72             my $fh = IO::File->new("> $dir_tot/$fn.pm");
73             $bean->write( $fh, $self );
74             }
75              
76             # Un-finalize the PerlBeans
77             foreach my $bean ( $self->values_perl_bean() ) {
78             $bean->_unfinalize();
79             }
80             THE_EOF
81             },
82             ],
83             } );
84              
85             sub get_syn {
86 1     1   5 use IO::File;
  1         2  
  1         169  
87             my $fh = IO::File->new('< syn-PerlBean_Collection.pl');
88             $fh = IO::File->new('< gen/syn-PerlBean_Collection.pl') if (! defined($fh));
89             my $syn = '';
90             my $prev_line = $fh->getline ();
91             while (my $line = $fh->getline ()) {
92             $syn .= ' ' . $prev_line;
93             $prev_line = $line;
94             }
95             return($syn);
96             }
97              
98             1;