 
	
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 2/6] osstest: introduce a helper to create a weblink to a directory
 Roger Pau Monne writes ("[Xen-devel] [PATCH 2/6] osstest: introduce a helper to 
create a weblink to a directory"):
> +sub create_weblink ($$$) {
> +    my ($ho, $tail, $target) = @_;
> +    my $wf_rhs= hostnamepath($ho)."_".$tail;
> +    my $wf_common= $c{WebspaceCommon}.$wf_rhs;
> +    my $wf_url= $c{WebspaceUrl}.$wf_common;
> +    my $wf_file= $c{WebspaceFile}.$wf_common;
> +
> +    unlink $wf_file;
> +    symlink $target, $wf_file or die "$wf_file $!";
> +    return $wf_url;
Most of this is the start of create_webfile.  Can you factor that
out ?
I have three suggestions for the shape:
      my ($wf_file, $wf_url) = prepare_create_webfile($ho, $tail);
      symlink $target, $wf_file or die "$wf_file $!";
      return $wf_url;
  }
      
or split create_webfile into create_web_fsobject which takes a
subref, and the call to file_link_contents:
      create_web_fsobject($ho, $tail, sub {
          my ($wf_file) = @_;
          symlink $target, $wf_file or die "$wf_file $!";
      });
  }
or the same but make passing a subref as $contents legal for
create_webfile,
 sub create_webfile ($$$) {
     my .... $contents_spec);
     # $contents as for file_link_contents, or a subref
     # which will be called as $contents_spec($wf_file,$wf_url);
     ...
     if (ref($contents_spec) ne 'CODE') {
         my $contents =  $contents_spec;
         $contents_spec = sub {
             my ($wf_file) = @_;
             file_link_contents($wf_file, $contents, "webspace-$wf_rhs");
         };
     }
Take your pick, or do something similar ?
Ian.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
 | 
|  | Lists.xenproject.org is hosted with RackSpace, monitoring our |