App/Plugin/MetaFile.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 53 CC 2 SCAR 11.5
CC
2
Cov
0%
load_file
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package Gapp::App::Plugin::MetaFile;
2 {
3 $Gapp::App::Plugin::MetaFile::VERSION = '0.007';
4 }
5  
6  
7 use Moose;
8 use MooseX::StrictConstructor;
9 use MooseX::SemiAffordanceAccessor;
10  
11 use File::Basename;
12  
13 use XML::LibXML;
14  
15 # remember where file is located
16  
17 has 'path' => (
18 is => 'rw',
19 isa => 'Str',
20 default => '',
21 trigger => sub { $_[0]->_clear_dir; },
22 );
23  
24 has 'dir' => (
25 is => 'rw',
26 isa => 'Str',
27 clearer => '_clear_dir',
28 default => sub {
29 my $dir = ( fileparse ( $_[0]->path ) )[1];
30 chop $dir;
31 return $dir;
32 },
33 lazy => 1,
34 );
35  
36  
37  
38  
39 # meta file attributes
40  
41 has [qw(author author_email author_url)] => (
42 is => 'rw',
43 isa => 'Str',
44 default => '',
45 );
46  
47 has [qw(copyright)] => (
48 is => 'rw',
49 isa => 'Str',
50 default => '',
51 );
52  
53 has 'creation_date' => (
54 is => 'rw',
55 isa => 'Str',
56 default => '',
57 );
58  
59 has 'description' => (
60 is => 'rw',
61 isa => 'Str',
62 default => '',
63 );
64  
65 has 'id' => (
66 is => 'rw',
67 isa => 'Str',
68 default => '',
69 );
70  
71 has 'license' => (
72 is => 'rw',
73 isa => 'Str',
74 default => '',
75 );
76  
77 has 'name' => (
78 is => 'rw',
79 isa => 'Str',
80 default => '',
81 );
82  
83 has 'version' => (
84 is => 'rw',
85 isa => 'Str',
86 default => '',
87 );
88  
89 has 'class' => (
90 is => 'rw',
91 isa => 'Str',
92 default => '',
93 );
94  
95  
96 # read an xml file
97  
98 sub load_file {
99 my ( $self, $path ) = @_;
100
101 $self->set_path( $path );
102
103 # load the document with LibXML
104 my $doc = XML::LibXML->load_xml( location => $path );
105
106 my $root = $doc->documentElement;
107
108 for ( qw(id author author_email author_url class copyright creation_date description license name version ) ) {
109 my $node = ($root->getChildrenByTagName( $_ ))[0];
110 next if ! $node;
111
112 my $value = $node->textContent;
113 my $writer = 'set_' . $_;
114 $self->$writer( $value );
115 }
116
117 }
118  
119 1;