| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Algorithm::Dependency::Source::File; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: File source for dependency hierarchies | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | #pod =pod | 
| 5 |  |  |  |  |  |  | #pod | 
| 6 |  |  |  |  |  |  | #pod =head1 DESCRIPTION | 
| 7 |  |  |  |  |  |  | #pod | 
| 8 |  |  |  |  |  |  | #pod Algorithm::Dependency::Source::File implements a | 
| 9 |  |  |  |  |  |  | #pod L where the items are stored in a flat | 
| 10 |  |  |  |  |  |  | #pod file or a relatively simple format. | 
| 11 |  |  |  |  |  |  | #pod | 
| 12 |  |  |  |  |  |  | #pod =head2 File Format | 
| 13 |  |  |  |  |  |  | #pod | 
| 14 |  |  |  |  |  |  | #pod The file should be an ordinary text file, consisting of a series of lines, | 
| 15 |  |  |  |  |  |  | #pod with each line completely containing the information for a single item. | 
| 16 |  |  |  |  |  |  | #pod Blank lines, or lines beginning with the hash character '#' will be | 
| 17 |  |  |  |  |  |  | #pod ignored as comments. | 
| 18 |  |  |  |  |  |  | #pod | 
| 19 |  |  |  |  |  |  | #pod For a single item line, only word characters will be used. A 'word character' | 
| 20 |  |  |  |  |  |  | #pod consists of all letters and numbers, and the underscore '_' character. | 
| 21 |  |  |  |  |  |  | #pod Anything that is not a word character will be assumed to be a separator. | 
| 22 |  |  |  |  |  |  | #pod | 
| 23 |  |  |  |  |  |  | #pod The first word will be used as the name or id of the item, and any further | 
| 24 |  |  |  |  |  |  | #pod words in the line will be used as other items that this one depends on. For | 
| 25 |  |  |  |  |  |  | #pod example, all of the following are legal. | 
| 26 |  |  |  |  |  |  | #pod | 
| 27 |  |  |  |  |  |  | #pod   # A single item with no dependencies | 
| 28 |  |  |  |  |  |  | #pod   Foo | 
| 29 |  |  |  |  |  |  | #pod | 
| 30 |  |  |  |  |  |  | #pod   # Another item that depends on the first one | 
| 31 |  |  |  |  |  |  | #pod   Bar Foo | 
| 32 |  |  |  |  |  |  | #pod | 
| 33 |  |  |  |  |  |  | #pod   # Depending on multiple others | 
| 34 |  |  |  |  |  |  | #pod   Bin Foo Bar | 
| 35 |  |  |  |  |  |  | #pod | 
| 36 |  |  |  |  |  |  | #pod   # We can use different separators | 
| 37 |  |  |  |  |  |  | #pod   One:Two|Three-Four+Five=Six Seven | 
| 38 |  |  |  |  |  |  | #pod | 
| 39 |  |  |  |  |  |  | #pod   # We can also use multiple non-word characters as separators | 
| 40 |  |  |  |  |  |  | #pod   This&*&^*&File:  is& & & :::REALLY()Neat | 
| 41 |  |  |  |  |  |  | #pod | 
| 42 |  |  |  |  |  |  | #pod From the examples above, it should be easy to create your own files. | 
| 43 |  |  |  |  |  |  | #pod | 
| 44 |  |  |  |  |  |  | #pod =head1 METHODS | 
| 45 |  |  |  |  |  |  | #pod | 
| 46 |  |  |  |  |  |  | #pod This documents the methods differing from the ordinary | 
| 47 |  |  |  |  |  |  | #pod L methods. | 
| 48 |  |  |  |  |  |  | #pod | 
| 49 |  |  |  |  |  |  | #pod =cut | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 7 |  |  | 7 |  | 3877 | use 5.005; | 
|  | 7 |  |  |  |  | 26 |  | 
| 52 | 7 |  |  | 7 |  | 35 | use strict; | 
|  | 7 |  |  |  |  | 13 |  | 
|  | 7 |  |  |  |  | 134 |  | 
| 53 | 7 |  |  | 7 |  | 43 | use Algorithm::Dependency::Source (); | 
|  | 7 |  |  |  |  | 14 |  | 
|  | 7 |  |  |  |  | 2618 |  | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | our $VERSION = '1.111'; | 
| 56 |  |  |  |  |  |  | our @ISA     = 'Algorithm::Dependency::Source'; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | ##################################################################### | 
| 62 |  |  |  |  |  |  | # Constructor | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | #pod =pod | 
| 65 |  |  |  |  |  |  | #pod | 
| 66 |  |  |  |  |  |  | #pod =head2 new $filename | 
| 67 |  |  |  |  |  |  | #pod | 
| 68 |  |  |  |  |  |  | #pod When constructing a new Algorithm::Dependency::Source::File object, an | 
| 69 |  |  |  |  |  |  | #pod argument should be provided of the name of the file to use. The constructor | 
| 70 |  |  |  |  |  |  | #pod will check that the file exists, and is readable, returning C | 
| 71 |  |  |  |  |  |  | #pod otherwise. | 
| 72 |  |  |  |  |  |  | #pod | 
| 73 |  |  |  |  |  |  | #pod =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub new { | 
| 76 | 9 |  |  | 9 | 1 | 3748 | my $class    = shift; | 
| 77 | 9 | 50 |  |  |  | 35 | my $filename = shift or return undef; | 
| 78 | 9 | 50 |  |  |  | 206 | return undef unless -r $filename; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | # Get the basic source object | 
| 81 | 9 | 50 |  |  |  | 82 | my $self = $class->SUPER::new() or return undef; | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | # Add our arguments | 
| 84 | 9 |  |  |  |  | 26 | $self->{filename} = $filename; | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 9 |  |  |  |  | 26 | $self; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | ##################################################################### | 
| 94 |  |  |  |  |  |  | # Private Methods | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub _load_item_list { | 
| 97 | 9 |  |  | 9 |  | 17 | my $self = shift; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | # Load the contents of the file | 
| 100 | 9 |  |  |  |  | 462 | local $/ = undef; | 
| 101 | 9 | 50 |  |  |  | 456 | open( FILE, $self->{filename} ) or return undef; | 
| 102 | 9 | 50 |  |  |  | 232 | defined(my $source = )    or return undef; | 
| 103 | 9 | 50 |  |  |  | 124 | close( FILE )                   or return undef; | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | # Split, trim, clean and remove comments | 
| 106 | 9 |  |  |  |  | 164 | my @content = grep { ! /^\s*(?:\#|$)/ } | 
|  | 110 |  |  |  |  | 316 |  | 
| 107 |  |  |  |  |  |  | split /\s*[\015\012][\s\015\012]*/, $source; | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | # Parse and build the item list | 
| 110 | 9 |  |  |  |  | 29 | my @Items = (); | 
| 111 | 9 |  |  |  |  | 46 | foreach my $line ( @content ) { | 
| 112 |  |  |  |  |  |  | # Split the line by non-word characters | 
| 113 | 94 |  |  |  |  | 296 | my @sections = grep { length $_ } split /\W+/, $line; | 
|  | 183 |  |  |  |  | 384 |  | 
| 114 | 94 | 50 |  |  |  | 221 | return undef unless scalar @sections; | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | # Create the new item | 
| 117 | 94 | 50 |  |  |  | 293 | my $Item = Algorithm::Dependency::Item->new( @sections ) or return undef; | 
| 118 | 94 |  |  |  |  | 237 | push @Items, $Item; | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 9 |  |  |  |  | 50 | \@Items; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | 1; | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | __END__ |