File Coverage

gen/attr-PerlBean_Symbol.pl
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 18 19 94.7


line stmt bran cond sub pod time code
1 1     1   5 use strict;
  1         2  
  1         155  
2              
3             push(@::bean_desc, {
4             bean_opt => {
5             abstract => 'Symbol in a Perl bean',
6             package => 'PerlBean::Symbol',
7             use_perl_version => 5.005,
8             description => <
9             C allows to specify, declare, assign an export a symbol from a C.
10             EOF
11             short_description => 'Symbol in a Perl bean',
12             synopsis => &get_syn(),
13             },
14             attr_opt => [
15             {
16             method_factory_name => 'declared',
17             type => 'BOOLEAN',
18             default_value => 1,
19             short_description => 'the symbol is to be declared with C',
20             },
21             {
22             method_factory_name => 'export_tag',
23             type => 'MULTI',
24             unique => 1,
25             short_description => 'the list of tags with which the symbol is exported. NOTE: The C tag lets the symbol be exported by default',
26             allow_rx => [ qw(^\S*$) ],
27             },
28             {
29             method_factory_name => 'symbol_name',
30             short_description => 'the symbol\'s name (e.g. C<$var> or C<@list>)',
31             allow_rx => [ qw(^\S+$) ],
32             },
33             {
34             method_factory_name => 'assignment',
35             short_description => 'the value assigned to the symbol during declaration',
36             },
37             {
38             method_factory_name => 'comment',
39             short_description => 'the comment for the symbol declaration',
40             },
41             {
42             method_factory_name => 'description',
43             short_description => 'the description of the symbol',
44             },
45             {
46             method_factory_name => 'volatile',
47             type => 'BOOLEAN',
48             short_description => 'the symbol is volatile',
49             },
50             ],
51             meth_opt => [
52             {
53             method_name => 'write',
54             parameter_description => 'FILEHANDLE',
55             description => <
56             Writes the code for the symbol. C is an C object.
57             EOF
58             body => <<'EOF',
59             my $self = shift;
60             my $fh = shift;
61              
62             # Do nothing if symbol should not be declared
63             $self->is_declared() || return;
64              
65             my $name = $self->get_symbol_name() || '';
66              
67             my $comment = $self->get_comment() || '';
68              
69             my $decl = $self->get_assignment() ?
70             "$AO=$AO" . $self->get_assignment() : ";\n";
71              
72             $fh->print( "${comment}our ${name}${decl}\n" );
73             EOF
74             },
75             ],
76             use_opt => [
77             {
78             dependency_name => 'PerlBean::Style',
79             import_list => [ 'qw(:codegen)' ],
80             },
81             ],
82             } );
83              
84             sub get_syn {
85 1     1   5 use IO::File;
  1         2  
  1         212  
86 1     1   6 my $fh = IO::File->new('< syn-PerlBean.pl');
87 1 50       65 $fh = IO::File->new('< gen/syn-PerlBean.pl') if (! defined($fh));
88 1         76 my $syn = '';
89 1         30 my $prev_line = $fh->getline ();
90 1         58 while (my $line = $fh->getline ()) {
91 18         413 $syn .= ' ' . $prev_line;
92 18         329 $prev_line = $line;
93             }
94 1         56 return($syn);
95             }
96              
97             1;