| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Algorithm::Dependency::Source::File; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =pod | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Algorithm::Dependency::Source::File - File source for dependency heirachys | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Algorithm::Dependency::Source::File implements a | 
| 12 |  |  |  |  |  |  | L where the items are stored in a flat | 
| 13 |  |  |  |  |  |  | file or a relatively simple format. | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head2 File Format | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | The file should be an ordinary text file, consisting of a series of lines, | 
| 18 |  |  |  |  |  |  | with each line completely containing the information for a single item. | 
| 19 |  |  |  |  |  |  | Blank lines, or lines beginning with the hash character '#' will be | 
| 20 |  |  |  |  |  |  | ignored as comments. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | For a single item line, only word characters will be used. A 'word character' | 
| 23 |  |  |  |  |  |  | consists of all letters and numbers, and the underscore '_' character. | 
| 24 |  |  |  |  |  |  | Anything that is not a word character will be assumed to be a seperator. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | The first word will be used as the name or id of the item, and any further | 
| 27 |  |  |  |  |  |  | words in the line will be used as other items that this one depends on. For | 
| 28 |  |  |  |  |  |  | example, all of the following are legal. | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # A single item with no dependencies | 
| 31 |  |  |  |  |  |  | Foo | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # Another item that depends on the first one | 
| 34 |  |  |  |  |  |  | Bar Foo | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # Depending on multiple others | 
| 37 |  |  |  |  |  |  | Bin Foo Bar | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | # We can use different seperators | 
| 40 |  |  |  |  |  |  | One:Two|Three-Four+Five=Six Seven | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # We can also use multiple non-word characters as seperators | 
| 43 |  |  |  |  |  |  | This&*&^*&File:  is& & & :::REALLY()Neat | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | From the examples above, it should be easy to create your own files. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | =head1 METHODS | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | This documents the methods differing from the ordinary | 
| 50 |  |  |  |  |  |  | L methods. | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =cut | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 7 |  |  | 7 |  | 6238 | use 5.005; | 
|  | 7 |  |  |  |  | 26 |  | 
|  | 7 |  |  |  |  | 490 |  | 
| 55 | 7 |  |  | 7 |  | 42 | use strict; | 
|  | 7 |  |  |  |  | 12 |  | 
|  | 7 |  |  |  |  | 314 |  | 
| 56 | 7 |  |  | 7 |  | 41 | use Algorithm::Dependency::Source (); | 
|  | 7 |  |  |  |  | 12 |  | 
|  | 7 |  |  |  |  | 160 |  | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 7 |  |  | 7 |  | 34 | use vars qw{$VERSION @ISA}; | 
|  | 7 |  |  |  |  | 20 |  | 
|  | 7 |  |  |  |  | 488 |  | 
| 59 |  |  |  |  |  |  | BEGIN { | 
| 60 | 7 |  |  | 7 |  | 20 | $VERSION = '1.110'; | 
| 61 | 7 |  |  |  |  | 3261 | @ISA     = 'Algorithm::Dependency::Source'; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | ##################################################################### | 
| 69 |  |  |  |  |  |  | # Constructor | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =pod | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head2 new $filename | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | When constructing a new Algorithm::Dependency::Source::File object, an | 
| 76 |  |  |  |  |  |  | argument should be provided of the name of the file to use. The constructor | 
| 77 |  |  |  |  |  |  | will check that the file exists, and is readable, returning C | 
| 78 |  |  |  |  |  |  | otherwise. | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =cut | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | sub new { | 
| 83 | 9 |  |  | 9 | 1 | 4393 | my $class    = shift; | 
| 84 | 9 | 50 |  |  |  | 37 | my $filename = shift or return undef; | 
| 85 | 9 | 50 |  |  |  | 244 | return undef unless -r $filename; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | # Get the basic source object | 
| 88 | 9 | 50 |  |  |  | 89 | my $self = $class->SUPER::new() or return undef; | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | # Add our arguments | 
| 91 | 9 |  |  |  |  | 25 | $self->{filename} = $filename; | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 9 |  |  |  |  | 32 | $self; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | ##################################################################### | 
| 101 |  |  |  |  |  |  | # Private Methods | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub _load_item_list { | 
| 104 | 9 |  |  | 9 |  | 14 | my $self = shift; | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | # Load the contents of the file | 
| 107 | 9 |  |  |  |  | 34 | local $/ = undef; | 
| 108 | 9 | 50 |  |  |  | 368 | open( FILE, $self->{filename} ) or return undef; | 
| 109 | 9 | 50 |  |  |  | 314 | defined(my $source = )    or return undef; | 
| 110 | 9 | 50 |  |  |  | 167 | close( FILE )                   or return undef; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | # Split, trim, clean and remove comments | 
| 113 | 9 |  |  |  |  | 164 | my @content = grep { ! /^\s*(?:\#|$)/ } | 
|  | 110 |  |  |  |  | 247 |  | 
| 114 |  |  |  |  |  |  | split /\s*[\015\012][\s\015\012]*/, $source; | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | # Parse and build the item list | 
| 117 | 9 |  |  |  |  | 28 | my @Items = (); | 
| 118 | 9 |  |  |  |  | 20 | foreach my $line ( @content ) { | 
| 119 |  |  |  |  |  |  | # Split the line by non-word characters | 
| 120 | 94 |  |  |  |  | 244 | my @sections = grep { length $_ } split /\W+/, $line; | 
|  | 183 |  |  |  |  | 299 |  | 
| 121 | 94 | 50 |  |  |  | 288 | return undef unless scalar @sections; | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | # Create the new item | 
| 124 | 94 | 50 |  |  |  | 293 | my $Item = Algorithm::Dependency::Item->new( @sections ) or return undef; | 
| 125 | 94 |  |  |  |  | 211 | push @Items, $Item; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 | 9 |  |  |  |  | 53 | \@Items; | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | 1; | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =pod | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =head1 SUPPORT | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | To file a bug against this module, use the CPAN bug tracking system | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | L | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | For other comments, contact the author. | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =head1 AUTHOR | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Adam Kennedy | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | L | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | Copyright 2003 - 2009 Adam Kennedy. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This program is free software; you can redistribute | 
| 156 |  |  |  |  |  |  | it and/or modify it under the same terms as Perl itself. | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | The full text of the license can be found in the | 
| 159 |  |  |  |  |  |  | LICENSE file included with this module. | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =cut |