]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
add type info to influence information
[ikiwiki.git] / IkiWiki.pm
index 73d2a9763107cfe918c17d6dbc27945b22a222f0..39a43ddbec4854261fafff1c9e12021b9e45db3e 100644 (file)
@@ -1772,52 +1772,34 @@ sub add_depends ($$;@) {
        my $page=shift;
        my $pagespec=shift;
 
-       # Is the pagespec a simple page name?
-       my $simple=$pagespec =~ /$config{wiki_file_regexp}/ &&
-               $pagespec !~ /[\s*?()!]/;
-
        my $deptype=0;
        if (@_) {
                my %params=@_;
                
-               if ($params{presence}) {
-                       # Is the pagespec limited to terms that will continue
-                       # to match pages as long as those pages exist?
-                       my $presence_limited=1;
-                       while ($presence_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
-                               $presence_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
-                       }
-                       if ($presence_limited) {
-                               $deptype=$deptype | $DEPEND_PRESENCE;
-                       }
-                       else {
-                               $deptype=$deptype | $DEPEND_CONTENT;
-                       }
-               }
-               if ($params{links}) {
-                       # Is the pagespec limited to terms that will continue
-                       # to match pages as long as those pages exist and
-                       # link to the same places?
-                       my $links_limited=1;
-                       while ($links_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
-                               $links_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after|backlink)$/;
-                       }
-                       if ($links_limited) {
-                               $deptype=$deptype | $DEPEND_LINKS;
-                       }
-                       else {
-                               $deptype=$deptype | $DEPEND_CONTENT;
-                       }
-               }
+               $deptype=$deptype | $DEPEND_PRESENCE if $params{presence};
+               $deptype=$deptype | $DEPEND_LINKS if $params{links};
        }
        $deptype=$DEPEND_CONTENT unless $deptype;
 
-       if ($simple) {
+       # Is the pagespec a simple page name?
+       if ($pagespec =~ /$config{wiki_file_regexp}/ &&
+           $pagespec !~ /[\s*?()!]/) {
                $depends_simple{$page}{lc $pagespec} |= $deptype;
                return 1;
        }
 
-       return unless pagespec_valid($pagespec);
+       # Analyse the pagespec, and match it against all pages
+       # to get a list of influences, and add explicit 
+       # content dependencies for those.
+       my $sub=pagespec_translate($pagespec);
+       return if $@;
+       foreach my $p (keys %pagesources) {
+               my $r=$sub->($p, location => $page );
+               my %i=$r->influences;
+               foreach my $i (keys %i) {
+                       $depends_simple{$page}{lc $i} |= $i{$i};
+               }
+       }
 
        $depends{$page}{$pagespec} |= $deptype;
        return 1;
@@ -2018,8 +2000,8 @@ use overload (
        '""'    => sub { $_[0][0] },
        '0+'    => sub { 0 },
        '!'     => sub { bless $_[0], 'IkiWiki::SuccessReason'},
-       '&'     => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] },
-       '|'     => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] },
+       '&'     => sub { $_[0]->merge_influences($_[1]); $_[0] },
+       '|'     => sub { $_[1]->merge_influences($_[0]); $_[1] },
        fallback => 1,
 );
 
@@ -2031,8 +2013,8 @@ use overload (
        '""'    => sub { $_[0][0] },
        '0+'    => sub { 1 },
        '!'     => sub { bless $_[0], 'IkiWiki::FailReason'},
-       '&'     => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] },
-       '|'     => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] },
+       '&'     => sub { $_[1]->merge_influences($_[0]); $_[1] },
+       '|'     => sub { $_[0]->merge_influences($_[1]); $_[0] },
        fallback => 1,
 );
 
@@ -2043,7 +2025,15 @@ sub new {
 }
 
 sub influences {
-       return keys %{$_[0][1]};
+       return %{$_[0][1]};
+}
+
+sub merge_influences {
+       my $this=shift;
+       my $other=shift;
+       foreach my $influence (keys %{$other->[1]}) {
+               $this->[1]{$influence} |= $other->[1]{$influence};
+       }
 }
 
 package IkiWiki::ErrorReason;
@@ -2099,23 +2089,24 @@ sub match_link ($$;@) {
        my $from=exists $params{location} ? $params{location} : '';
 
        my $links = $IkiWiki::links{$page};
-       return IkiWiki::FailReason->new("$page has no links") unless $links && @{$links};
+       return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS)
+               unless $links && @{$links};
        my $bestlink = IkiWiki::bestlink($from, $link);
        foreach my $p (@{$links}) {
                if (length $bestlink) {
-                       return IkiWiki::SuccessReason->new("$page links to $link")
+                       return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS)
                                if $bestlink eq IkiWiki::bestlink($page, $p);
                }
                else {
-                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
+                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS)
                                if match_glob($p, $link, %params);
                        my ($p_rel)=$p=~/^\/?(.*)/;
                        $link=~s/^\///;
-                       return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link")
+                       return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS)
                                if match_glob($p_rel, $link, %params);
                }
        }
-       return IkiWiki::FailReason->new("$page does not link to $link");
+       return IkiWiki::FailReason->new("$page does not link to $link", $page => $IkiWiki::DEPEND_LINKS);
 }
 
 sub match_backlink ($$;@) {
@@ -2131,14 +2122,14 @@ sub match_created_before ($$;@) {
 
        if (exists $IkiWiki::pagectime{$testpage}) {
                if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
-                       return IkiWiki::SuccessReason->new("$page created before $testpage");
+                       return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
                else {
-                       return IkiWiki::FailReason->new("$page not created before $testpage");
+                       return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
        }
        else {
-               return IkiWiki::ErrorReason->new("$testpage does not exist");
+               return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
        }
 }
 
@@ -2151,14 +2142,14 @@ sub match_created_after ($$;@) {
 
        if (exists $IkiWiki::pagectime{$testpage}) {
                if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
-                       return IkiWiki::SuccessReason->new("$page created after $testpage");
+                       return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
                else {
-                       return IkiWiki::FailReason->new("$page not created after $testpage");
+                       return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
                }
        }
        else {
-               return IkiWiki::ErrorReason->new("$testpage does not exist");
+               return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
        }
 }